gcc 由于无法识别 __TIMESTAMP__ 和其他一些已定义的构建变量而生成编译时错误
gcc generate compile time error because of unabling to recognize __TIMESTAMP__ and some other defined build variable
我正在使用基于 IDE 的 eclipse 和 GCC 的现有示例来为嵌入式 EFTPOS 设备编译我的应用程序。
但在下面几行中:
fprintf(stdout, "** Compilation date: %s \n", __TIMESTAMP__);
fprintf(stdout, "**** SDK release: %s \n", __SDK_RELEASE__);
fprintf(stdout, "**** ToolChain release: %s \n", __TOOLCHAIN_RELEASE__);
我收到这些编译时错误,似乎编译器无法识别这些宏。
Symbol '__TIMESTAMP__' could not be resolved main.c
Symbol '__SDK_RELEASE__' could not be resolved main.c
Symbol '__TOOLCHAIN_RELEASE__' could not be resolved main.c
如果我尝试 fprintf(stdout, "** Compilation date: %s \n", __TIME__);
它编译成功。
为什么编译器识别 __TIME__
宏但 return 错误 __TIMESTAMP__
?同样如您所见,__SDK_RELEASE__
和 __TOOLCHAIN_RELEASE__
是在构建变量中定义的。
编辑:
感谢您的回复,请原谅我缺少所提供的信息。
在 C/C++ build ->setting->symbols:
'__SDK_RELEASE__="${SDK_RELEASE}"'
'__TOOLCHAIN_RELEASE__="${TOOLCHAIN_RELEASE}"'
被定义,那么 __SDK_RELEASE__
和 __TOOLCHAIN_RELEASE__
必须是 valid.Also 我的意思是如果 __TIME__
宏是有效的 __TIMESTAMP__
必须做同样的事情,但是它不是。
您在构建变量中定义了 SDK_RELEASE
和 TOOLCHAIN_RELEASE
,为什么要使用双下划线??..
将代码更改为
fprintf(stdout, "**** SDK release: %s \n", SDK_RELEASE);
fprintf(stdout, "**** ToolChain release: %s \n", TOOLCHAIN_RELEASE);
关于 __TIME__
, as you can see, macros are defined since c99 和 "double underscores",这就是它起作用的原因。
形成C11
6.4.2.2 Predefined identifiers
Semantics
1 The identifier __func__
shall be implicitly declared by the translator as if,
immediately following the opening brace of each function definition, the declaration
static const char func[] = "function-name";
appeared, where function-name is the name of the lexically-enclosing function.72)
note.72 Since the name __func__
is reserved for any use by the implementation (7.1.3), if any other
identifier is explicitly declared using the name __func__
, the behavior is undefined.
强调我的
6.10.8.1 Mandatory macros
1 The following macro names shall be defined by the implementation:
__DATE__
The date of translation of the preprocessing translation unit: a character
string literal of the form "Mmm dd yyyy", where the names of the
months are the same as those generated by the asctime function, and the
first character of dd is a space character if the value is less than 10. If the
date of translation is not available, an implementation-defined valid date
shall be supplied.
__FILE__
The presumed name of the current source file (a character string literal).
__LINE__
The presumed line number (within the current source file) of the current
source line (an integer constant).
__STDC__
The integer constant 1, intended to indicate a conforming implementation.
__STDC_HOSTED__
The integer constant 1 if the implementation is a hosted
implementation or the integer constant 0 if it is not.
__STDC_VERSION__
The integer constant 201112L.
__TIME__
The time of translation of the preprocessing translation unit: a character
string literal of the form "hh:mm:ss" as in the time generated by the
asctime function. If the time of translation is not available, an
implementation-defined valid time shall be supplied.
强调我的
7.1.3 Reserved identifiers
1 Each header declares or defines all identifiers listed in its associated subclause, and
optionally declares or defines identifiers listed in its associated future library directions
subclause and identifiers which are always reserved either for any use or for use as file
scope identifiers.
— All identifiers that begin with an underscore and either an uppercase letter or another
underscore are always reserved for any use.
— All identifiers that begin with an underscore are always reserved for use as identifiers
with file scope in both the ordinary and tag name spaces.
[...]
强调我的
如您所见,__TIMESTAMP__
定义不在标准中,因此编译器可以自由定义或不定义它:您当前的编译器没有。
我正在使用基于 IDE 的 eclipse 和 GCC 的现有示例来为嵌入式 EFTPOS 设备编译我的应用程序。 但在下面几行中:
fprintf(stdout, "** Compilation date: %s \n", __TIMESTAMP__);
fprintf(stdout, "**** SDK release: %s \n", __SDK_RELEASE__);
fprintf(stdout, "**** ToolChain release: %s \n", __TOOLCHAIN_RELEASE__);
我收到这些编译时错误,似乎编译器无法识别这些宏。
Symbol '__TIMESTAMP__' could not be resolved main.c
Symbol '__SDK_RELEASE__' could not be resolved main.c
Symbol '__TOOLCHAIN_RELEASE__' could not be resolved main.c
如果我尝试 fprintf(stdout, "** Compilation date: %s \n", __TIME__);
它编译成功。
为什么编译器识别 __TIME__
宏但 return 错误 __TIMESTAMP__
?同样如您所见,__SDK_RELEASE__
和 __TOOLCHAIN_RELEASE__
是在构建变量中定义的。
编辑: 感谢您的回复,请原谅我缺少所提供的信息。 在 C/C++ build ->setting->symbols:
'__SDK_RELEASE__="${SDK_RELEASE}"'
'__TOOLCHAIN_RELEASE__="${TOOLCHAIN_RELEASE}"'
被定义,那么 __SDK_RELEASE__
和 __TOOLCHAIN_RELEASE__
必须是 valid.Also 我的意思是如果 __TIME__
宏是有效的 __TIMESTAMP__
必须做同样的事情,但是它不是。
您在构建变量中定义了 SDK_RELEASE
和 TOOLCHAIN_RELEASE
,为什么要使用双下划线??..
将代码更改为
fprintf(stdout, "**** SDK release: %s \n", SDK_RELEASE);
fprintf(stdout, "**** ToolChain release: %s \n", TOOLCHAIN_RELEASE);
关于 __TIME__
, as you can see, macros are defined since c99 和 "double underscores",这就是它起作用的原因。
形成C11
6.4.2.2 Predefined identifiers
Semantics
1 The identifier
__func__
shall be implicitly declared by the translator as if, immediately following the opening brace of each function definition, the declarationstatic const char func[] = "function-name";
appeared, where function-name is the name of the lexically-enclosing function.72)
note.72 Since the name
__func__
is reserved for any use by the implementation (7.1.3), if any other identifier is explicitly declared using the name__func__
, the behavior is undefined.
强调我的
6.10.8.1 Mandatory macros
1 The following macro names shall be defined by the implementation:
__DATE__
The date of translation of the preprocessing translation unit: a character string literal of the form "Mmm dd yyyy", where the names of the months are the same as those generated by the asctime function, and the first character of dd is a space character if the value is less than 10. If the date of translation is not available, an implementation-defined valid date shall be supplied.
__FILE__
The presumed name of the current source file (a character string literal).
__LINE__
The presumed line number (within the current source file) of the current source line (an integer constant).
__STDC__
The integer constant 1, intended to indicate a conforming implementation.
__STDC_HOSTED__
The integer constant 1 if the implementation is a hosted implementation or the integer constant 0 if it is not.
__STDC_VERSION__
The integer constant 201112L.
__TIME__
The time of translation of the preprocessing translation unit: a character string literal of the form "hh:mm:ss" as in the time generated by the asctime function. If the time of translation is not available, an implementation-defined valid time shall be supplied.
强调我的
7.1.3 Reserved identifiers
1 Each header declares or defines all identifiers listed in its associated subclause, and optionally declares or defines identifiers listed in its associated future library directions subclause and identifiers which are always reserved either for any use or for use as file scope identifiers.
— All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.
— All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces.
[...]
强调我的
如您所见,__TIMESTAMP__
定义不在标准中,因此编译器可以自由定义或不定义它:您当前的编译器没有。