c - 尝试编译简单的inotify程序

标签 c linux

我正在尝试在内核版本为 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/

相关文章:

c++ - v4l2 很简单的例子

linux - 使用 .env 文件运行 shell 脚本

C - 找到一个单词并获取接下来的两个单词

c - -> 和 . 之间的区别在结构中?

c - 栈和堆的内存分配量(c)

c - select() 返回无效参数

c - 这个简单的 C 程序有什么问题?

linux - 从 bash 中的 Json 中提取值

linux - QEMU 在 Eclipse 中运行正常,但在调试时失败

linux - 如何为匿名上传服务 file.io 创建 bashrc 脚本?