【发布时间】:2015-12-16 19:15:06
【问题描述】:
这是要重现的最小 C 程序:
#include <alsa/asoundlib.h>
#include <sys/time.h>
int main( void )
{
}
这将使用gcc -c -o timealsa.o timealsa.c 进行编译,但如果包含-std=c99 开关,则会出现重新定义错误:
In file included from /usr/include/sys/time.h:28:0,
from timealsa.c:3:
/usr/include/bits/time.h:30:8: error: redefinition of ‘struct timeval’
struct timeval
^
In file included from /usr/include/alsa/asoundlib.h:49:0,
from timealsa.c:2:
/usr/include/alsa/global.h:138:8: note: originally defined here
struct timeval {
^
如何在仍然使用-std=c99 的同时解决此冲突?
【问题讨论】:
-
您应该使用 main 的最低标准,即 int main(void){return 0;}
-
是的,你是对的(但那是另一行!)
-
@Michi
return 0是隐含的,如果在 C99 中不存在(这个问题被标记)。请参阅:stackoverflow.com/questions/4138649/why-is-return-0-optional。空白是个问题 -
由于问题集中在 c99 标准上,我将使其更符合标准。
-
这是个坏主意,恕我直言,因为
main()不应该是“特殊的”。但实际上,这与这里完全无关。顺便说一句,int main(void)也很好。
标签: gcc compiler-errors x86 c99 alsa