对变量i的未定义引用

时间:2011-06-11 17:05:53

标签: c

这是我的代码

#include<stdio.h>
 main ()
{
        extern int i;
        i=20;
     printf("%d",i);
}

当我编译它时,我收到错误

ka2.c: In function ‘main’:
ka2.c:6: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long unsigned int’
/tmp/ccGXrSE5.o: In function `main':
**ka2.c:(.text+0x6): undefined reference to `i'**
collect2: ld returned 1 exit status

我想知道我用粗体加工的线条出错的原因。

2 个答案:

答案 0 :(得分:4)

您已声明i但尚未定义,这就是链接器抱怨的原因。

答案 1 :(得分:2)

你宣称我是外在的。删除此关键字可以解决问题,因为extern意味着在另一个模块中定义的内容

相关问题