gcc 컴파일 warning : implicit declaration of function 'pread' 및 pwrite

ygt의 이미지

검색 많이 해봤는데 다 일반적인 경우고 지금 저처럼 꼬인 경우는 좀처럼 검색에 물리지가 않네요.

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);
}
cinsk의 이미지


헤더를 포함시키기 전에 다음과 같은 매크로를 선언하기 바랍니다.

#define _XOPEN_SOURCE  500

이런 매크로에 대해 좀 더 알고 싶다면 "info libc feature"를 실행하기 바랍니다.

--
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Korean Ver: http://www.cinsk.org/cfaqs/

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.