multiply defined link errors

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

Parents
  • "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...

Reply
  • "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...

Children
More questions in this forum