在一个头文件main.h中仿照CW自带头文件定义了一些变量: typedef union { byte Byte; struct { byte BITR0 :1; byte BITR1 :1; byte BITR2 :1; byte BITR3 :1; byte BITR4 :1; byte BITR5 :1; byte BITR6 :1; byte BITR7 :1; } Bits; } Myflag; extern volatile Myflag _MYFLAG0,_MYFLAG1,_MYFLAG2,_MYFLAG3,_MYFLAG4,_MYFLAG5,_MYFLAG6; #define FLAG0 _MYFLAG0.Byte #define FLAG0_B0 _MYFLAG0.Bits.BITR0 #define FLAG0_B1 _MYFLAG0.Bits.BITR1 #define FLAG0_B2 _MYFLAG0.Bits.BITR2 #define FLAG0_B3 _MYFLAG0.Bits.BITR3 #define FLAG0_B4 _MYFLAG0.Bits.BITR4 #define FLAG0_B5 _MYFLAG0.Bits.BITR5 #define FLAG0_B6 _MYFLAG0.Bits.BITR6 #define FLAG0_B7 _MYFLAG0.Bits.BITR7 #define FLAG0_B0_MASK 1 #define FLAG0_B1_MASK 2 #define FLAG0_B2_MASK 4 #define FLAG0_B3_MASK 8 #define FLAG0_B4_MASK 16 #define FLAG0_B5_MASK 32 #define FLAG0_B6_MASK 64 #define FLAG0_B7_MASK 128 ------------------------------------------------------------------------------------------------------------------------------------ 而后在源文件ECT.c中包含该头文件,并且使用定义的变量 #include <mc9s12xd256.h> /* derivative information */ #include "main.h" FLAG0_B2=0; //UOUT_R=0 ------------------------------------------------------------------------------ 编译时提示: External object _MYFLAG0 in ECT.c.o created by default 看帮助内容如下: Unresolved external. The specified symbol is referenced in the file specified, but is not defined anywhere in the application, but an external declaration for this object is available in at least one of the binary file. The object is supposed to be defined in the first binary file where it is externally defined. This is only valid for ANSI-C applications 似乎是说我定义的变量被引用了,但是没有在程序中定义(define),但是这个变量又被申明(declaration)为全局变量。 我不太理解定义与申明的区别啊,我不是在main.h中定义了变量吗?在使用之前也通过include加入了该头文件啊?怎么还要重新定义?我看使用自带头文件的变量时好像只要include就OK啊,编译也没问题。比如直接用PTH_PTH0=1;则不会出现问题 |