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

MULTIPLE PUBLIC DEFINITIONS

I define a variable

unsigned char c
 in a file A.h and include it in A.c and another file B.c in which the variable is being used.

Then I face a linker error of multiple public definitions.

PS: The variable is declared once for sure.
    The usual way of making header files is used. 
#ifndef
 etc.

Can anyone help me remove this error? I'll be very grateful.

Parents
  • "I define a variable

    unsigned char c

    in a file A.h and include it in A.c and another file B.c in which the variable is being used."


    Thus both A.c and B.c contain a definition of this variable, don't they?

    So you will obviously get a "multiple definitions" error!

    Instead you should define the variable in just one of your .c files, and provide and extern declaration in the header file.

Reply
  • "I define a variable

    unsigned char c

    in a file A.h and include it in A.c and another file B.c in which the variable is being used."


    Thus both A.c and B.c contain a definition of this variable, don't they?

    So you will obviously get a "multiple definitions" error!

    Instead you should define the variable in just one of your .c files, and provide and extern declaration in the header file.

Children
No data