【问题标题】:Gcc error: 'NULL' and 'stderr' undeclaredGcc 错误:未声明“NULL”和“stderr”
【发布时间】:2017-11-27 05:33:52
【问题描述】:

我将 gcc 4.6.0 用于 armv7。今天我需要编译这个源码:

#include <sys/types.h>
#include <dirent.h>
int main(void)
{
    DIR *dir = opendir(".");
    if(dir)
    {
        struct dirent *ent;
        while ((ent = readdir(dir)) != NULL)
        {
            puts(ent->d_name);
        }
    }
    else
    {
        fprintf(stderr, "Error opening directory\n");
    }
    return 0;
}

在编译时出现了这样的错误:

test.c:在函数'main'中:test.c:10:31:错误:'NULL'未声明 (在此函数中首次使用)test.c:10:31: 注意:每个未声明 标识符对于它出现的每个函数只报告一次 test.c:17:1:警告:内置的隐式声明不兼容 函数'fprintf' [默认启用] test.c:17:9: error: 'stderr' 未声明(在此函数中首次使用)

我该如何解决这个问题?

【问题讨论】:

    标签: gcc


    【解决方案1】:

    添加以下包括:

    #include <stdio.h>
    

    【讨论】:

    • 谢谢,我已经准备好了
    猜你喜欢
    • 2010-11-23
    • 1970-01-01
    • 2015-02-20
    • 2010-10-02
    • 2014-12-08
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多