我正在尝试在内核版本为 2.6.15 的 Ubuntu 6.06.2 上编译 inotify simpe 代码。 我的代码是
#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'.
请有人告诉我如何解决这个问题。
最佳答案
inotify.h 必须存在于系统路径中。
即/usr/include/i386-linux-gnu/sys/inotify.h
sys/inotify.h 不是标准库的一部分! (然而,它是 Linux 机器上通常可用的库的一部分)
关于c - 尝试编译简单的inotify程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41546106/