即使添加了#include ,也会隐式声明popen
这是我的代码的一小部分。
#include #include #include #include #include #include #include #include #include #include #include #include ... FILE * pipe; ... pipe = popen ("ls /tmp -1", "r"); ... pclose(pipe);
blarg.c:106: warning: implicit declaration of function 'popen' blarg.c:106: warning: assignment makes pointer from integer without a cast blarg.c:112: warning: implicit declaration of function 'pclose' blarg.c:118: warning: assignment makes pointer from integer without a cast
我真的不确定。 我查了一下popen,它需要的是stdio.h。 缺少什么,或者是我的其余代码中的问题(我真的不想显示更多代码,因为它是一个赋值)。
正如手册页所说:
Feature Test Macro Requirements for glibc (see feature_test_macros(7)): popen(), pclose(): _POSIX_C_SOURCE >= 2 || _XOPEN_SOURCE || _BSD_SOURCE || _SVID_SOURCE
因此,在#include
stdio.h
之前,你应该#define _BSD_SOURCE
或其中一个。
用-std=gnu99
或-std=gnu11
替换-std=c99
或-std=c11
等。
我把popen和pclose的原型放在我的代码顶部。 它似乎解决了这个问题。