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: symbol "_malloc" redefined

Other Parts Discussed in Thread: CCSTUDIO

I am in the process of migrating a C5510 project to run in DSP/BIOS.  I'm pretty much done but am having problems with dynamic memory.  The program uses the library functions minit() and calloc().  When I build the project, I get the following linker errors:

<Linking>
error: symbol "_free" redefined: first defined in
   "C:/CCStudio_v3.3/bios_5_33_03/packages/ti/bios/lib/bios.a55L<malloc.o55L>";
   redefined in "C:/CCStudio_v3.3/UpgradesAndPackages/C5500 Code Generation
   Tools 4.3.1/lib/rts55x.lib<memory.obj>"
error: symbol "_calloc" redefined: first defined in
   "C:/CCStudio_v3.3/bios_5_33_03/packages/ti/bios/lib/bios.a55L<malloc.o55L>";
   redefined in "C:/CCStudio_v3.3/UpgradesAndPackages/C5500 Code Generation
   Tools 4.3.1/lib/rts55x.lib<memory.obj>"
error: symbol "_realloc" redefined: first defined in
   "C:/CCStudio_v3.3/bios_5_33_03/packages/ti/bios/lib/bios.a55L<malloc.o55L>";
   redefined in "C:/CCStudio_v3.3/UpgradesAndPackages/C5500 Code Generation
   Tools 4.3.1/lib/rts55x.lib<memory.obj>"
error: symbol "_malloc" redefined: first defined in
   "C:/CCStudio_v3.3/bios_5_33_03/packages/ti/bios/lib/bios.a55L<malloc.o55L>";
   redefined in "C:/CCStudio_v3.3/UpgradesAndPackages/C5500 Code Generation
   Tools 4.3.1/lib/rts55x.lib<memory.obj>"

If I comment out the code containing the function calls, the program builds.  Can someone help me understand why this happens and how to fix it?  I thought DSP/BIOS allowed for the use of dynmaic memory allocation...

Mike

  • Note that BIOS automatically includes rts55x.lib in the generated linker command file.  Have you added that library either as a file to the project or in the linker options?  I just did a quick test and see similar errors if I do that.

    FYI, although you can use malloc() with BIOS there is another API called MEM_alloc that you can also use with BIOS.  The advantage of MEM_alloc is that it allows you to have multiple heaps and also to request a specific alignment.

  • Brad,

    I can check this but the linker error specifically startes it's first defined in a BIOS lib and then redefined in rts55x.lib.  Does your suggestion address that?

    btw, I'll switch to the BIOS APIs at some point.  First step is to get the program running in BIOS without as few changes as possible...

     

    thanks,

    Mike

  • Mike,

    I actually created a test case and tested this out myself.  I was seeing similar behavior where I would get errors about definitions in both the BIOS library and the rts library.  The only thing I changed in my code was adding an additional include of rts55x.lib in my linker options.

    Brad

  • Brad,

    ok - I did the same thing as you and can now successfully build the project.  Do you know WHY this additional include is needed?  The <projname>cfg.cmd file already contains the following line:

    -lrts55x.lib           /* C and C++ run-time library support */

    so why does it need to be included again???

    Mike

  • I was seeing the opposite issue.  That is, have it included twice caused problems.  That's not what you're seeing?  It seemed reasonable that having it included twice would cause a "symbol redefined" error.

  • According to your test, you say you added rts55x.lib in the project configuration.  I assume you did this via Project->Build Options...<linker tab> <Libraries category> and typed in rts55x.lib.  This is what I just did.  But don't you also have the library included in the BIOS generated .cmd file for the project, "-lrts55x.lib"??

    Mike

  • By going to Project -> Build Options -> Linker -> Libraries and adding rts55x.lib (i.e. second inclusion) I was able to CREATE the error.  Removing the additional inclusion got rid of the error.   Is that what you see?

  • Brad,

    I got side-tracked on some stuff and just now getting back to this.  We have opposite results.  On my project, the error goes away when I add the rts55x.lib in the build options --> linker tab.  When I remove it so only the BIOS cmd file includes it, do I get the error.

    So I can use this as a work around (including it with the linker tab and letting BIOS include it).  However, this seems strange to both of us that it would work like this.  Do you have any more thoughts on the what could be wrong?

  • After more testing, this workaround will not work.  Even though the code builds w/o errors, it does not execute correctly; BIOS crashes.  My current fix is to remove the code that causes the link error (e.g. any calls to the standard dynamic memory allocation  routines in stddef.h).

    So the build process is not working right.  It's allowing 2 includes of the rts55x.lib and then during runtime when execution goes through main and drops to the BIOS idle loop, the program crashes.

  • After a little more testing and consulting with Brad, it turns out the culprit is a function called minit().  This function seems to be allowed in a non-BIOS project, but causes problems in a BIOS project.  The easy work around is to not use this function and this option will work in my case.  There are still a few unanswered items related to this issue.  If anyone would like to share info, please post them in this thread:

    1.  Where is minit() defined?  The link error is not that minit is an unresolved symbol, it's that something is being redefined...

    2. Why does this function call work in a non-BIOS project but does NOT work in a BIOS project?

    3. It seems if you use the function in a BIOS-project, you can resolve the link error by including the library rts55x.lib in the linker tab of the project build options.  However, the program will not execute correctly.  It will progress through main and when it drops into the BIOS kernel (idle loop), it crashes.

  •  

    Mike said:
    1.  Where is minit() defined?  The link error is not that minit is an unresolved symbol, it's that something is being redefined...

    inside the RTS (run-time support library)

    Mike said:
    2. Why does this function call work in a non-BIOS project but does NOT work in a BIOS project?

    Please see: http://tiexpressdsp.com/index.php/DSP_BIOS_FAQ#Q:_Can_runtime_support_.28RTS.29_functions_be_called_when_using_DSP.2FBIOS.3F

  • Mike said:

    1.  Where is minit() defined?  The link error is not that minit is an unresolved symbol, it's that something is being redefined...

    2. Why does this function call work in a non-BIOS project but does NOT work in a BIOS project?

    3. It seems if you use the function in a BIOS-project, you can resolve the link error by including the library rts55x.lib in the linker tab of the project build options.  However, the program will not execute correctly.  It will progress through main and when it drops into the BIOS kernel (idle loop), it crashes.

    minit() is not an ANSI defined/required RTS function.  The RTS library happens to supply this function regardless.  However, BIOS has its own implementation of malloc, i.e. MEM_alloc.  It has re-written many of these functions.  When you call minit() you end up linking in code from the RTS library.  In this scenario you end up with a mix of memory allocation code from BIOS and the codegen -- not good.  If using BIOS it's best to avoid using minit().