读书人

为什么extern不起作用,该如何解决

发布时间: 2012-02-06 15:52:44 作者: rapoo

为什么extern不起作用
/*file1.c*/
int aaa=1;

/*file2.c*/
#include <stdio.h>

extern int aaa;

int main()
{
printf("%d\n",aaa);

return 0;
}
我使用linux下的gcc编译器。

[everett@localhost do]$ gcc file2.c
/home/everett/tmp/ccmSoags.o: In function `main':
file2.c:(.text+0x12): undefined reference to `aaa'
collect2: ld returned 1 exit status

为什么extern不起作用?


[解决办法]
It's a link error, you should compile file1.c as well

读书人网 >C语言

热点推荐