如何修复'函数'pipe2'的隐式声明在C99中无效'

Car*_*rgo 5 c c99

我正在尝试构建我的库,但是一个名为 evutil.c fom libevent 的文件给我带来了困难。

libevent/evutil.c: error: implicit declaration of function 'pipe2' is invalid in C99

涉及的代码是:

    if (pipe2(fd, O_NONBLOCK|O_CLOEXEC) == 0)
        return 0;
Run Code Online (Sandbox Code Playgroud)

我现在无法将代码更新为 c11。我应该如何更改代码以不再出现此错误?

Sch*_*ern 2

这不是 C99 问题。您需要包含 的标头pipe2根据pipe2手册unistd.h

为什么 libevent 本身不这样做是一个有效的问题。