2017-01-09 177 views
-1

我想在内核版本2.6.15的Ubuntu 6.06.2上编译inotify simpe代码。 我的代码是试图编译简单的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); 
} 

我已经安装的libc6-dev的2.3.6也。 但是当我编译这段代码有

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

,当我用linux/inotify.h比我得到

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

请有人告诉我怎样才能解决这个问题。

+0

'Inotify被合并到2.6.13 Linux内核中。所需的库接口已添加到版本2.4中的glibc。 (在glib 2.5版中增加了IN_DONT_FOLLOW,IN_MASK_ADD和IN_ONLYDIR)。所以我认为你需要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

我如何在ubuntu中创建这个“/usr/include/i386-linux-gnu/sys/inotify.h”路径。我应该为此安装一些软件包或库 –