问题描述
这是我代码的小片段.
#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
我真的不确定.我抬起头,所有它所需的只是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所以你应该#define _BSD_SOURCE或#include ing stdio.h之前的其他一个.
其他推荐答案
用-std=gnu99或-std=gnu11替换-std=c99或-std=c11等.
其他推荐答案
我将popen和pclose的原型放在我的代码的顶部.似乎已经解决了这个问题.
相关问答
相关标签/搜索