我目前正在为AVR ATMega8微控制器开发一个项目。假设我有多个文件:
INIT.C:
__no_init __regvar unsigned char flags@ 4;
__no_init __regvar unsigned char tb_flags@ 5;
__no_init __regvar unsigned char st_flags@ 6;
__no_init __regvar unsigned char dp_flags@ 7;
__no_init __regvar unsigned char g83_flags@ 8;
__no_init __regvar unsigned char ms_flags@ 9;
__no_init __regvar unsigned char co_flags@ 10;
__no_init __regvar unsigned char tm_cs5460@ 11;
__no_init __regvar unsigned char tm_noZX@ 12;
__no_init __regvar unsigned char tm_state@ 13;
使用该代码我告诉编译器我想使用寄存器来存储全局变量(memmory optimization)。该文件包括下一个文件Defines.h
Defines.h:
extern __no_init __regvar unsigned char flags@ 4;
extern __no_init __regvar unsigned char tb_flags@ 5;
extern __no_init __regvar unsigned char st_flags@ 6;
extern __no_init __regvar unsigned char dp_flags@ 7;
extern __no_init __regvar unsigned char g83_flags@ 8;
extern __no_init __regvar unsigned char ms_flags@ 9;
extern __no_init __regvar unsigned char co_flags@ 10;
extern __no_init __regvar unsigned char tm_cs5460@ 11;
extern __no_init __regvar unsigned char tm_noZX@ 12;
extern __no_init __regvar unsigned char tm_state@ 13;
我这样做是因为我的项目中的每个文件都包含了define.h。有了这个,我认为所有全局变量的范围都是整个项目,但我得到一个奇怪的错误:
Error[e46]: Undefined external "st_flags" referred in main ( C:\Users\Alex\Desktop\CentroStirling\Progreso\MSUIAR\Debug\Obj\main.r90 )
Error[e46]: Undefined external "dp_flags" referred in main ( C:\Users\Alex\Desktop\CentroStirling\Progreso\MSUIAR\Debug\Obj\main.r90 )
Error[e46]: Undefined external "g83_flags" referred in main ( C:\Users\Alex\Desktop\CentroStirling\Progreso\MSUIAR\Debug\Obj\main.r90 )
Error[e46]: Undefined external "flags" referred in main ( C:\Users\Alex\Desktop\CentroStirling\Progreso\MSUIAR\Debug\Obj\main.r90 )
Error[e46]: Undefined external "co_flags" referred in main ( C:\Users\Alex\Desktop\CentroStirling\Progreso\MSUIAR\Debug\Obj\main.r90 )
Error[e46]: Undefined external "tm_noZX" referred in main ( C:\Users\Alex\Desktop\CentroStirling\Progreso\MSUIAR\Debug\Obj\main.r90 )
Error[e46]: Undefined external "tm_state" referred in main ( C:\Users\Alex\Desktop\CentroStirling\Progreso\MSUIAR\Debug\Obj\main.r90 )
如果仔细观察,有10个全局变量,只有7个错误。这意味着其中一些被认可......
我该怎么做才能解决这个问题?