This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

*** ERROR L104: MULTIPLE PUBLIC DEFINITIONS

I have Declared all my declaration in one file called ADeclaration.h and included this file in all my module C files.

i.e.

i have

 MAIN.c (MAIN)
 Port_IO.c (PORT_IO)
 STORAGE.c (STORAGE)
 TEMPERATURE.c (TEMPERATURE)
 CONVERT.c (CONVERT)
 UART.c (UART)
 RTC.c (RTC)
 I2C.c (I2C)
 ISR.c(ISR)
 FLASH.c (FLASH)

All the declaration of this files are in Adeclaration.h

now i am getting my project.M51 with
Program Size: data=157.5 xdata=5988 code=11148
LINK/LOCATE RUN COMPLETE. 29 WARNING(S), 294 ERROR(S)

and the target is not created

most of the error are like

*** ERROR L104: MULTIPLE PUBLIC DEFINITIONS
    SYMBOL:  LOCAL
    MODULE:  STORAGE.obj

Parents
  • If you have:

    int my_variable;
    


    in a header file and includes it from multiple c files, you will get problems. Then every c file that includes the header fle will try to create a variable "my_variable", and the linker will be unhappy.

    If you have:

    extern int my_variable;
    


    in the header file, then no c file will create any variable with that name, but they will know that somewhere there should exist such a variable. The c code will be happy but the linker will still be unhappy - this time about a missing symbol.

    So - in your header file you should write:

    extern int my_variable;
    


    and then in one (1) c file you should have a line:

    int my_varible;
    


    or maybe:

    int my_variable = 127;
    


    Then all c files that includes the header file will know about the existence of the variable. But the linker will find exactly one file that actually creates such a variable.

    By the way - this isn't something unique to embedded programming. Any text book about the C programming language will tell you about the use of variables in multiple modules and the use of the "extern" keyword.

Reply
  • If you have:

    int my_variable;
    


    in a header file and includes it from multiple c files, you will get problems. Then every c file that includes the header fle will try to create a variable "my_variable", and the linker will be unhappy.

    If you have:

    extern int my_variable;
    


    in the header file, then no c file will create any variable with that name, but they will know that somewhere there should exist such a variable. The c code will be happy but the linker will still be unhappy - this time about a missing symbol.

    So - in your header file you should write:

    extern int my_variable;
    


    and then in one (1) c file you should have a line:

    int my_varible;
    


    or maybe:

    int my_variable = 127;
    


    Then all c files that includes the header file will know about the existence of the variable. But the linker will find exactly one file that actually creates such a variable.

    By the way - this isn't something unique to embedded programming. Any text book about the C programming language will tell you about the use of variables in multiple modules and the use of the "extern" keyword.

Children