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.

MSP430FR2355: error on redefining variables?

Part Number: MSP430FR2355

I have created a library with a header file and source file.  Within the header file I have :

const int lookup[] = {0, 529, 715, 835, 1001, 1252, 1430, 1670, 2147, 2224, 2503, 3000, 3333, \
                    3575, 3753, 4003, 4286, 4378, 5002, 5715, 6003, 6254, 6432, 6667, 7001, \
                    7147, 7503, 7861, 8004, 8333, 8464, 8572, 8751, 9004, 9170, 9288};
const int reg_setting[] = {0x0, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x11, 0x21, 0x22, \
                           0x44, 0x25, 0x49, 0x4A, 0x52, 0x92, 0x53, 0x55, 0xAA, \
                           0x6B, 0xAD, 0xB5, 0xB6, 0xD6, 0xB7, 0xBB, 0xDD, 0xED, \
                           0xEE, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0xFE};

The source file within this library uses this.  I can then successfully compile the library.  I then go to my main application and link the library successfully.  However when I try and build the main application I get the following errors:

error #10056: symbol "reg_setting" redefined: first defined in "./main.obj"; redefined in "D:/Customers/Firmware/LPRS_lib/Debug/LPRS_lib.lib<lprs_mspConfig.obj>"
error #10056: symbol "lookup" redefined: first defined in "./main.obj"; redefined in "D:/Customers/Firmware/LPRS_lib/Debug/LPRS_lib.lib<lprs_mspConfig.obj>"

There is no reference at all in any of the application code with respect to these variables.  Can someone tell me what is going on and how to fix?

Thanks

  • Your header needs to have an extern declaration and you need to define it one time in a source file. Since these are global variables, there can be only one definition, or the linker gets confused. You *do* refer to them in the source file when you #include it.

  • These const int arrays are literally used by a function that performs math within a library.  Within the application code I pass parameters to the function that have nothing to do with the const int arrays. I want the library to be self contained.  There are no switches in CCS to suggest to the compiler as it compiles the application that this is defined within a library?  Maybe I am confused here.  It appears if I remove the const int arrays from the library header file and place them within the function scope of the library source file the main application source code (a completely different prj by the way) compiles without errors.  Unless there is a reason not to do this it seems like the way to go??

    I'd prefer in the end not to have the customer who will create source code independently having to place library dependencies all throughout their code with extern and defines....

  • Put the array in the source file, not the header file. You only have to put it in the header file if you want it available to other source files.

  • If you want private data and public data, you might want 2 headers. A public one and a private one.

**Attention** This is a public forum