c - 即使添加了 #include <stdio.h> 也隐式声明了 popen

标签 c declaration pipe implicit stdio

这是我的一小段代码。

   #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。缺少什么,或者是我的其余代码中的问题(我真的不想显示更多代码,因为它是一个作业)。

最佳答案

正如手册页所说:

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

popen(), pclose(): _POSIX_C_SOURCE >= 2 || _XOPEN_SOURCE || _BSD_SOURCE
|| _SVID_SOURCE

因此,在 #includeing stdio.h 之前,您应该#define _BSD_SOURCE 或其他之一。

关于c - 即使添加了 #include <stdio.h> 也隐式声明了 popen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5468326/

相关文章:

对UTC感到困惑

css - 为什么 CSS 类声明不适用于标记的 <div>?

java - 可以使用 Pipe 消除 TCP 碎片吗?

bash - 如何从 stdout 传递值作为下一个命令的参数

c - OpenMP:访问冲突和其他错误

c - 如何从 Check Point 设备提取 Check Point 日志

java - Android Studio变量最终声明问题

linux - 在 linux 中,使用 pipe() 从 fork 进程调用 system()

c - 如何将字符串的副本复制到适当大小的动态分配的字符数组中?

java - Java 声明困惑