I am converting a program that was generated using the Atollic tool chain, which uses the GNU compiler. After cleaning up a few small syntax differences, I am getting a L6200E multiply defined symbol error from the linker.
The project includes the following files: main.c, main.h, UARTMain.c, Utilities.c, fpDefs.h, STM32_Common.c, and STM32_Common.h.
STM32_Common.c includes STM32_Common.h, which also includes main.h. Main.c, UARTMain.c, and Utilities.c, all include main.h. Main.h has the normal #ifndef __MAIN_H_ | #define __MAIN_H_ protection from getting included twice.
It appears to me that main.h is getting included more than once as variables that are referenced in main.c and one of the other *.c file generate the linker error. This program compiles and runs fine in the Atollic environment.
Tom
"Main.h has the normal #ifndef __MAIN_H_ | #define __MAIN_H_ protection from getting included twice."
Note that this only prevents it from being included twice in the same compilation unit - it does not prevent it from being included in multiple compilation units.
This almost certainly means that you have definitions in the header file(s).
If a header file contains definitions, and that header file is included in multiple compilation units, that will obviously lead to multiple definitions!
You need to ensure that the headers contain only declarations - not definitions
c-faq.com/.../decldef.html
Note that some linkers (I think GCC's is one) can spot such multiple definitions and decide to "merge" them into one - which may be why your project builds "fine" (sic) on the other system...
Hey i have same problem. As u pointed in your reply that header files should contain only the declarations. I have done the same.
I have to made saveral .c files and for each .c file i have made a .h file which contains only functions declarations & variable declarations.
But still myltiply defined error occurs.
Please help.
Multiply defined what? You can't ask "please help" unless you also spend the time to actually present the error messages verbatim and do show the declarations with the names mentioned in the error messages. We do not have access to your source code. And we can't guess what you may be seeing.