popen方法隐含声明,即使&#包括LT; stdio.h中>加 [英] popen implicitly declared even though #include <stdio.h> is added

查看:212
本文介绍了popen方法隐含声明,即使&#包括LT; stdio.h中>加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code的微小片段。

This is tiny snippet of my code.

   #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中。什么是缺少的,或者是在我的code其余的问题(我真的不希望表现出更多的code,因为它是一个分配)。

I'm really unsure. I looked up popen and all it requires is stdio.h which is provided. What is missing, or is the problem in the rest of my code (I don't really want to show more code because its an a assignment).

推荐答案

由于该男子网页显示:

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

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

所以,你应该的#define _BSD_SOURCE 或其他人之前的#include ING stdio.h中

So you should #define _BSD_SOURCE or one of the others before #includeing stdio.h.

这篇关于popen方法隐含声明,即使&#包括LT; stdio.h中&GT;加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆