这是我的一小段代码。
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
...
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。缺少了什么,或者说是我代码其余部分的问题(我真的不想显示更多的代码,因为这是一个赋值)。
5条答案
按热度按时间vlurs2pr1#
将
-std=c99
或-std=c11
等替换为-std=gnu99
或-std=gnu11
。dm7nw8vv2#
正如man page所说:
所以你应该在
#include
和stdio.h
之前输入#define _BSD_SOURCE
或其他值。inkz8wg93#
我在MinGW遇到了这个问题;在它的stdio.h中,我发现:
结果我在gcc命令行上使用了
-DNO_OLDNAMES=1
来修复另一个源文件中的一些模糊问题,我甚至记不起来了。这是我的简单解决方案:cwtwac6a4#
正如@Conrad Mayer等其他人评论的那样。
Succinty,只需添加
说明
popen()函数是POSIX标准的一部分,它的声明可能依赖于正确定义的功能测试宏。这应该确保popen()的必要声明可用。
如果问题仍然存在,您可以尝试在包含头文件之前定义_GNU_SOURCE,因为popen()也是一个GNU扩展:
h7appiyu5#
我把popen和pclose的原型放在代码的顶部。看来问题解决了。