PZhx09 2018-03-21 04:02 采纳率: 100%
浏览 2745
已采纳

linux下C语言使用stdio.h库中popen和pclose函数编译报错

error: implicit declaration of function ‘popen’; did you mean ‘fopen’? [-Werror=implicit-function-declaration]
error: implicit declaration of function ‘pclose’; did you mean ‘fclose’? [-Werror=implicit-function-declaration]
请问下为什么这样会报隐式声明错误呀?

源代码如下:

        GList *fList = s_wEntries;
        s_wEntries=NULL;
        FILE *fstream=NULL;
        char buff[1024];
        memset(buff,0,sizeof(buff));
        // execute command get all video
        char *launchword="find / -name *";
        strcat(launchword,cText);
        strcat(launchword,"*");
        if(NULL==(fstream=popen(launchword,"r")))
        {


        }
        else
        {
            memset(buff, 0x00, sizeof(buff));
            FileEntryInfo *Finfo;
            GtkMenuItem* searchmenuitem;
            while(NULL!=fgets(buff, sizeof(buff), fstream)){
                   if(buff[0]=='/')
                   {


                        searchmenuitem=gtk_menu_item_new_with_label(buff);
                        Finfo->uri=buff;
                        Finfo->pMenuItem=searchmenuitem;
                        g_list_prepend(s_wEntries,Finfo);   
                   }

                memset(buff, 0x00, sizeof(buff));
            }
            pclose(fstream);
        }
  • 写回答

4条回答 默认 最新

  • YenZiHua 2018-03-21 05:04
    关注

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

    glibc是否支持这两个函数,需要测试上面的几个宏是否define了。如果这几个宏有任意一个define,则支持,否则就是不支持啦。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题