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.

TMS320F28379D: Symbol redefined error when using a structure defined in library

Part Number: TMS320F28379D


Dear team,

One of my customers is using their customized library.

In this library, they defined a structure in Define.h:

Then a structure is declared in a c file in the library:

The library can be built successfully with no error.

Then the library is included in the project. Since they still want to use the cputoclaRegs in the project(other .c not included in the lib), they defined the structure again in another Init_CLA.h file.

And declared in a c file:

The following error shows up:

symbol "_cputoclaRegs" redefined: first defined in "../lib/ME1500D0U211-Arith-cla.lib<ConstTab_J.obj>"; redefined in "../lib/ME1500D0U211-Arith-cla.lib<Svpwm_J.obj>" symbol "_cputoclaRegs" redefined: first defined in "../lib/ME1500D0U211-Arith-cla.lib<ConstTab_J.obj>"; redefined in "../lib/ME1500D0U211-Arith-cla.lib<Svpwm_J.obj>"

It seems cputoclaRegs is indeed defined twice both in library and out of library. However, if we really need to use cputoclaRegs in the main c files, we have to declare it again. Is there any method we can avoid this problem? Did we code in a right way?

Thanks!

  • Hi,

    If you struct is defined in your library and you need to use the same in your c file, you can declare the struct as extern in your c file as shown below:
    extern volatile struct ....;
    This tells the compiler that the struct is defined somewhere else and it can be accessed from the c file using this extern declaration.
    In fact, I see that this extern declaration is already available in the define.h header file. You can just include this file in our c file instead.

    Regards,
    Veena
  • Hi Veena,
    Thanks for your reply.
    Now I am suggesting my customer to do as following:
    1. Define a structure in a header file. Let's say define.h. In this file, we only define a structure following this format:

    struct CLA1TOCPU_REGS
    {
    };

    struct CPUTOCLA1_REGS
    {
    };

    2. In library .c file, include define.h and declare a CLA1TOCPU_REGS clattocpuRegs. Then use DATA_SECTION() to allocate it into MSGRAM:
    #include "define.h"
    #pragma DATA_SECTION(clatocpuRegs,"Cla1ToCpuMsgRAMA")
    volatile struct CLA1TOCPU_REGS clatocpuRegs;

    #pragma DATA_SECTION(cputoclaRegs,"CpuToCla1MsgRAMA")
    volatile struct CPUTOCLA1_REGS cputoclaRegs;

    3. Include the library in the project. In other .c files, include define.h and declare clattocpuRegs with 'extern':
    #include "define.h"
    #define MARITH_EXT extern
    MARITH_EXT volatile struct CLA1TOCPU_REGS clatocpuRegs;
    MARITH_EXT volatile struct CPUTOCLA1_REGS cputoclaRegs;

    I believe this should be the right way to handle the common used structure. However, the error still happens in debug build mode. In release build mode, everything is fine. Could you please help to identify the possible reasons?

    Thanks!
  • HI,

    This seems to be the correct approach. I am not sure why you still get the redefinition error. I hope the macro MARITH_EXT is defined as extren for both debug and release builds.
    Have you, by any chance, declared the struct without extern in any other c or header file? The compiler error message should actually indicate where the redefinition has occurred.

    Regards,
    Veena

  • Hi,

    Just wanted to followup. Were you able to figure out the reason for the error?

    Regards,
    Veena
  • Hi Veena,

    It turns out the problem is caused by writing CLAtoRAM regitster in project .c file. After they delete the related code and re-write following the procedures I summarzied above. The problem is solved.

    Thanks for your kindly supporting and follow up!

    Regards,
    Brian