gcc 컴파일 warning : implicit declaration of function 'pread' 및 pwrite
검색 많이 해봤는데 다 일반적인 경우고 지금 저처럼 꼬인 경우는 좀처럼 검색에 물리지가 않네요.
implicit declaration of function '함수명'
선언되지 않은 함수를 사용해서 생기는 경고라고 합니다.
(C에서는 경고 C++은 에러..)
경고라서 컴파일이 되긴 하지만 제대로 실행되지 않습니다.
그래서 반드시 잡아야 하는건데 컴파일을 돌려보면
implicit declaration of function 'pread'
implicit declaration of function 'pwrite'
이렇게 두개가 뜹니다. 함수를 선언 안해줬다?ㅡㅡ;;
저거 헤더파일에 들어있는거죠.
unistd.h
물론...선언되어있습니다. 선언되어있는데 어째서인지 제대로 인식을 못하고 저런 에러를 냅니다.
그럼 헤더파일을 제대로 인식 못하는 것인가? 생각했는데..
그건 또 아닙니다.
소스 코드에서 #include 부분을 주석처리하고 컴파일 시켜보면
pread, pwrite 이외에도
implicit declaration of function 'close'
implicit declaration of function 'dup'
implicit declaration of function 'unlink'
와 같이 워닝이 추가로 발생합니다.
그럼 제가 생각 할 수 있는게
내 컴퓨터의 unistd.h 에 뭔가 손상이 와서 딴건 다 제대로 있는데 pread, pwrite만 찾을 수 없다 ??????????
석연치가 않네요;;
해결책 부탁드립니다. __);
*** 추가적인 삽질 ?
unistd.h 파일이 5개나 존재하고 있길래 그냥 몽땅다 include 해봤습니다.
unistd.h
/usr/include/asm/unistd.h
/usr/include/unistd.h
/usr/include/bits/unistd.h
/usr/include/linux/unistd.h
/usr/include/sys/unistd.h
총 6개의 중복.. 근데 전부 다 그냥 같은 파일인지 이것도 전혀 효과가 없네요.
누가좀 살려주세요 ㅠㅜ
이하는 소스 코드 첨부합니다.
/*
FUSE: Filesystem in Userspace
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
This program can be distributed under the terms of the GNU GPL.
See the file COPYING.
gcc -Wall `pkg-config fuse --cflags --libs` -lulockmgr fusemy_fh.c -o fusemy_fh
*/
#define FUSE_USE_VERSION 26
#define _GNU_SOURCE
#include <fuse.h>
#include <ulockmgr.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h> // mytery
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/xattr.h>
#include <sys/mount.h>
static int my_getattr(const char *path, struct stat *stbuf)
{
int res;
res = lstat(path, stbuf);
if (res == -1)
return -errno;
return 0;
}
static inline DIR *get_dirp(struct fuse_file_info *fi)
{
return (DIR *) (uintptr_t) fi->fh;
}
static int my_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi)
{
DIR *dp = get_dirp(fi);
struct dirent *de;
(void) path;
seekdir(dp, offset);
while ((de = readdir(dp)) != NULL) {
struct stat st;
memset(&st, 0, sizeof(st));
st.st_ino = de->d_ino;
st.st_mode = de->d_type << 12;
if (filler(buf, de->d_name, &st, telldir(dp)))
break;
}
return 0;
}
static int my_unlink(const char *path)
{
int res;
res = unlink(path);
if (res == -1)
return -errno;
return 0;
}
static int my_create(const char *path, mode_t mode, struct fuse_file_info *fi)
{
int fd;
fd = open(path, fi->flags, mode);
if (fd == -1)
return -errno;
fi->fh = fd;
return 0;
}
static int my_open(const char *path, struct fuse_file_info *fi)
{
int fd;
fd = open(path, fi->flags);
if (fd == -1)
return -errno;
fi->fh = fd;
return 0;
}
static int my_read(const char *path, char *buf, size_t size, off_t offset,
struct fuse_file_info *fi)
{
int res;
(void) path;
res = pread(fi->fh, buf, size, offset);
if (res == -1)
res = -errno;
return res;
}
static int my_write(const char *path, const char *buf, size_t size,
off_t offset, struct fuse_file_info *fi)
{
int res;
(void) path;
res = pwrite(fi->fh, buf, size, offset);
if (res == -1)
res = -errno;
return res;
}
static int my_flush(const char *path, struct fuse_file_info *fi)
{
int res;
(void) path;
res = close(dup(fi->fh));
if (res == -1)
return -errno;
return 0;
}
static int my_release(const char *path, struct fuse_file_info *fi)
{
(void) path;
close(fi->fh);
return 0;
}
static struct fuse_operations my_oper = {
.getattr = my_getattr,
.readdir = my_readdir,
.open = my_open,
.read = my_read,
.write = my_write,
.create = my_create,
.unlink = my_unlink,
.flush = my_flush,
.release = my_release,
};
int main(int argc, char *argv[])
{
umask(0);
return fuse_main(argc, argv, &my_oper, NULL);
}

헤더를 포함시키기
헤더를 포함시키기 전에 다음과 같은 매크로를 선언하기 바랍니다.
이런 매크로에 대해 좀 더 알고 싶다면 "info libc feature"를 실행하기 바랍니다.
--
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Korean Ver: http://www.cinsk.org/cfaqs/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Korean Ver: http://cinsk.github.io/cfaqs/
댓글 달기