This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

error #10056: symbol "x" redefined: first defined in "./main.obj"; redefined in "./macLayer.obj"

I am a little bit confused here i didnot define symbol "x" in the main but the code composer showing me error (linking error) i coudnot able to find a solution ,can somebody tell me the solution!!!

  • Binyam Shiferaw said:
    i didnot define symbol "x" in the main

    Did you define it in a header included by main.c, and also included by macLayer.c ... ?

  • Andy Neil said:
    Did you define it in a header included by main.c, and also included by macLayer.c ... ?

    To be more specific:

    something like

    unsigned char x;

    is a declaration. It may appear as often as you want, is usually placed into a .h header file and included into many .c files. If it isn't preceded by 'extern', it will also cause an implicit generation by the linker as uninitialized variable, if x is used but not defined in any of the code files.

    unsigned char x = 0;

    is a definition. It creates a variable called 'x'. There must not be more than one global definition of a variable, so this kind of code goes into one, and only one .c file. This .c file may but doesn't need to include the .h file with the declaration.

  • Jens-Michael Gross said:
    unsigned char x;

    is a declaration. It may appear as often as you want, is usually placed into a .h header file and included into many .c files. If it isn't preceded by 'extern', it will also cause an implicit generation by the linker as uninitialized variable, if x is used but not defined in any of the code files.

    In other words, it is a tentative definition - that is, if no other definition is found, it will become the definition.

    In summary:

    • extern unsigned char x;     is a declaration;
    •        unsigned char x;     is a declaration and may also become a definition;
    •        unsigned char x = 0; is a definition.

    For this reason, you should be sure that your header files contain only declarations!

    http://c-faq.com/decl/decldef.html

    Suggested 'C' reference materials: http://blog.antronics.co.uk/2010/12/12

     

  • Thank you both now it is working,it was my header file!!

  • Just in case this might help someone with similar multiple defines, I found that this can happen if you have a duplicate file in the project / workspace path.  Somehow I ended up with another main.c before the source directory and even when I renamed it to something else, the compiler saw all the stuff in it and gave these same basic errors.


    Live and learn

    boB

  • Robin Gudgel said:
    this can happen if you have a duplicate file in the project

    Yes - clearly, if the file is duplicated, that will cause all its public definitions to be duplicated!

**Attention** This is a public forum