Linking error: undefined symbol
Hello,
I'm using CrossStudio for MSP430 Release 2.0.9.2010033104.7366.
I definitions.h file in which I define a global variable:
extern unsigned char Flag1;
In other .c file, main.c, that includes the previous .h., I initialize and use this flag:
Flag1 = 0;
if(Flag1 & F1_TestVolConst)...
The compilation runs fine, but the linking outputs the following error:
c:/projects/arad/software/octave rowley/main.c(348): error: undefined symbol '_Flag1'
Why does it happen? Definitions.h is included in main.c!
If I define the flag without the "extern" command, I get linking error about duplicate symbol in the definition place - in definitions.h
Thanks!
-
You need to put an "unsigned char Flag1;" in one of your C files in order to define the variable.
Adding "extern" just declares the variable it does not define it.
If you put the definition in your header file and include that header file from multiple C files the variable will be defined in each of those C files, hence the duplicate symbol error.
-
Thank you.
A short reading of the following article also helped me to understand the difference between declaring and defining:
Please sign in to leave a comment.
Comments
2 comments