2017-01-09 12 views
-1

私はUbuntu 6.06.2でinotify simpeコードをカーネルバージョン2.6.15でコンパイルしようとしています。 私のコードは私もあります:libc6-devの2.3.6をインストールしている単純なinotifyプログラムをコンパイルしようとしています

#include <errno.h> 
#include <poll.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <sys/inotify.h> 
#include <unistd.h> 
#include <fcntl.h> 

#define IN_NONBLOCK O_NONBLOCK 


int main(int argc, char* argv[]) 
{ 
     char buf; 
     int fd, i, poll_num; 
     int *wd; 
     nfds_t nfds; 
     struct pollfd fds[2]; 

     if (argc < 2) { 
       printf("Usage: %s PATH [PATH ...]\n", argv[0]); 
       exit(EXIT_FAILURE); 
     } 

     printf("Press ENTER key to terminate.\n"); 

     /* Create the file descriptor for accessing the inotify API */ 

     fd = inotify_init(); 
     if (fd == -1) { 
       perror("inotify_init1"); 
       exit(EXIT_FAILURE); 
     } 


     close(fd); 

     exit(EXIT_SUCCESS); 
} 

です。 しかし、ときに私はこのコードをコンパイルするには、

error: sys/inotify.h: No such file or directory 

を持って、私は

/tmp/ccUTUEAq.o: In function `main':ionotify.c:(.text+0x50): undefined reference to `inotify_init'. 

を得たよりも、私は、Linux/inotify.hを使用するときに誰かが、私はこの問題を解決する方法を教えてください。

+0

'Inotifyは2.6.13 Linuxカーネルにマージされました。必要なライブラリインタフェースがバージョン2.4のglibcに追加されました。 (IN_DONT_FOLLOW、IN_MASK_ADD、IN_ONLYDIRはglibバージョン2.5で追加されました) '。ですから、libcの更新が必要だと思います – pbn

+0

[inotify_initのマニュアルページ](http://man7.org/linux/man-pages/man2/inotify_init.2.html)を見ると、glibcにサポートが追加されました2.4。あなたは(非常に古い!)システムをアップグレードする必要があります。 –

+0

クイックレスポンスのおかげで.. –

答えて

-1

inotify.hがシステムパスに存在する必要があります。

すなわち/usr/include/i386-linux-gnu/sys/inotify.h

SYS/inotify.hは、標準ライブラリの一部ではありません! (ただし、通常はLinuxのボックスで利用できるライブラリの一部です)

+0

私はこれを "/usr/include/i386-linux-gnu/sys/inotify.h"のパスにすることができます。これはubuntu.shouldでいくつかのパッケージやライブラリをインストールしました。 –

関連する問題