首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

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

2012-02-06 
为什么extern不起作用/*file1.c*/int aaa1/*file2.c*/#include stdio.hextern int aaaint main(){pri

为什么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

热点排行