main.c 赋值
deng=1;
inf.h定义
int deng;
inf.c判断
void iff(void){
if(deng==1){}
}
test.c调用iff
为什么只定义了一遍的deng,会出错误提示重复定义。
Error: L6200E: Symbol deng multiply defined (by inf.o and main.o).
Error: L6200E: Symbol deng multiply defined (by test.o and main.o).
Not enough information to list image symbols.
Not enough information to list the image map.
求解
应该是因为你在inf.h中定义了全局变量,main.c和inf.c都包含了inf.h这个头文件
在编译时,因为每个c文件都会生成一个obj文件,你的main.o, 和inf.o都会包含deng这个全局变量的定义
在链接的时候,连接器就会发现deng这个变量被重定义了
正确的做法是:不要在头文件中定义全局变量,其他源文件如果想要使用全局变量可以加extern声明