简体   繁体   English

sys / stat.h:456:错误:嵌套函数“ stat”声明为“ extern”

[英]sys/stat.h:456: error: nested function 'stat' declared 'extern'

I have a program which I made by modifing many places from original darknet (deep learning image recognition, Yolov2). 我有一个程序,是通过从原始的Darknet(深度学习图像识别,Yolov2)中修改许多地方而成的。 I've been using it until several months ago, but today when I compile it, it gave me an error below : 直到几个月前我一直在使用它,但是今天当我对其进行编译时,它在下面给了我一个错误:

gcc  -DSAVE_LAYER_INPUTS -DSAVE_INPUTS_LAYER_START=31 -DSAVE_INPUTS_LAYER_END=31 -DPRINT_INOUT -Wall -Wfatal-errors  -O3 -ffast-math -c ./src/convolutional_layer.c -o obj/convolutional_layer.o
In file included from ./src/convolutional_layer.c:463:
/usr/include/sys/stat.h: In function 'forward_convolutional_layer':
/usr/include/sys/stat.h:456: error: nested function 'stat' declared 'extern'

I used stat.h to check if a directory exists and if not, to make it. 我使用stat.h检查目录是否存在,如果不存在,则进行创建。 This error comes at the line #include and inside stat.h file. 该错误出现在#include行和stat.h文件中。 I looked into stat.h, but can't tell what's wrong. 我调查了stat.h,但无法判断出什么问题。 stat.h looks like this (I showed which one is line 456.) stat.h看起来像这样(我显示了其中一个是456行。)

#if defined __GNUC__ && __GNUC__ >= 2 && defined __USE_EXTERN_INLINES
/* Inlined versions of the real stat and mknod functions.  */

__extern_inline int
__NTH (stat (__const char *__path, struct stat *__statbuf))
{     // <=== line 456
  return __xstat (_STAT_VER, __path, __statbuf);
}

__NTH is just adding an attribute about throw. __NTH只是添加了关于throw的属性。 What is the problem? 问题是什么? (using gcc 4.4.7 on CentOS 6.9) (在CentOS 6.9上使用gcc 4.4.7)

In general, system headers have to be included outside of any functions in your code. 通常,系统标头必须包含在代码中任何函数的外部。 The C11 standard says §7.1.2 Standard headers (emphasis added): C11标准规定§7.1.2标准标头 (添加了强调):

¶4 Standard headers may be included in any order; ¶4标准头文件可以以任何顺序包括在内; each may be included more than once in a given scope, with no effect different from being included only once, except that the effect of including <assert.h> depends on the definition of NDEBUG (see §7.2). 在给定范围内,每个元素都可以被多次包含,除了包含<assert.h>的效果取决于NDEBUG的定义(参见§7.2)外,其他效果与仅被包含一次相同。 If used, a header shall be included outside of any external declaration or definition, and it shall first be included before the first reference to any of the functions or objects it declares, or to any of the types or macros it defines. 如果使用头,则头应包含在任何外部声明或定义之外,并且应首先包含在对它声明的任何函数或对象,或其定义的任何类型或宏的第一次引用之前。 However, if an identifier is declared or defined in more than one header, the second and subsequent associated headers may be included after the initial reference to the identifier. 但是,如果在一个以上的标头中声明或定义了一个标识符,则可以在对标识符的初始引用之后包含第二个和后续关联的标头。 The program shall not have any macros with names lexically identical to keywords currently defined prior to the inclusion of the header or when any macro defined in the header is expanded. 该程序不得包含名称与在包含头之前或扩展头中定义的任何宏时当前定义的关键字在词法上相同的宏。

I've not found the equivalent wording in POSIX, but you should assume that similar rules apply. 我在POSIX中找不到等效的措词,但是您应该假定适用类似的规则。

Given the error message mentioning 'nested functions', it is likely that you're trying to include #include <sys/stat.h> from inside the scope of one of your functions, and given that the header defines some inline functions, you are accidentally trying to define those as nested functions, which is not allowed in general (though GCC has some support for nested function, but you should probably regard that as unportable). 鉴于错误消息中提到“嵌套函数”,您很可能试图在其中一个函数的作用域内包含#include <sys/stat.h> ,并且鉴于标头定义了一些内联函数,偶然地试图将它们定义为嵌套函数,这通常是不允许的(尽管GCC对嵌套函数有一定的支持,但是您可能应该将其视为不可移植的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM