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.

Linker error from C++ call C library file

Other Parts Discussed in Thread: SYSBIOS

Hi,

I am using EVM6678 board. The Big_time project and MCSDK example 1: led_play both correctly run. The linker does know the library path. I would like to combine the LED function to big_time project. Of course, I use the same library path as the separate projects above. Unfortunately, there is a linker error. See below please:

.........

'Invoking: C6000 Linker'

"C:/Program Files (x86)/Texas Instruments/C6000 Code Generation Tools 7.4.2/bin/cl6x" -mv6600 --abi=eabi -g --display_error_number --diag_warning=225 --diag_wrap=off -z --stack_size=0x8000 -m"big_time_LED.map" --heap_size=0x8000 -i"C:/Program Files (x86)/Texas Instruments/C6000 Code Generation Tools 7.4.2/lib" -i"C:/ti/pdk_C6678_1_1_2_5/packages/ti/platform/evmc6678l/platform_lib/lib/debug" -i"C:/Program Files (x86)/Texas Instruments/C6000 Code Generation Tools 7.4.2/include" --reread_libs --warn_sections --display_error_number --diag_wrap=off --rom_model -o "big_time_LED.out" -l"./configPkg/linker.cmd"  "./bigtime.obj" -l"libc.a" -lti.platform.evm6678l.ae66 "../big_time.cmd"

<Linking>

undefined                                                  first referenced                                                                            

  symbol                                                        in file                                                                                 

---------                                                  ----------------                                                                            

platform_led(unsigned int, PLATFORM_LED_OP, LED_CLASS_E)   ./bigtime.obj                                                                               

platform_delay(unsigned int)                               ./bigtime.obj                                                                               

ti_sysbios_BIOS_start__E                                   ./bigtime.obj                                                                               

ti_sysbios_family_c64p_TimestampProvider_Module_startup__F C:\Users\Jeff\workspace_v5_1_C6678\big_time_LED\Debug\configPkg\package\cfg\bigtime_pe66.oe66

error #10234-D: unresolved symbols remain

error #10010: errors encountered during linking; "big_time_LED.out" not built

....................

Even I reduce the big_time project to a simple idle task after removing all other stuff, the same error exists.

Is this related to name mangling? But after I include platform_led and platform_delay declaration to:

extern "C" {

/* Wrapper functions to call Clock::tick() */

void clockIdle(void);

Platform_STATUS platform_led(uint32_t led_id, PLATFORM_LED_OP operation, LED_CLASS_E led_class);

Platform_STATUS platform_delay(uint32_t usecs);

}

// end extern "C"

The errors are:

........

"../bigtime.cpp", line 103: error #339: linkage specification is incompatible with previous "platform_led" (declared at line 995 of "C:\ti\pdk_C6678_1_1_2_5\packages\ti\platform\platform.h")

"../bigtime.cpp", line 104: error #339: linkage specification is incompatible with previous "platform_delay" (declared at line 1007 of "C:\ti\pdk_C6678_1_1_2_5\packages\ti\platform\platform.h")

2 errors detected in the compilation of "../bigtime.cpp".

.............

The compiler complains the incompatibility.

I create another C (not C++ project) with one idle task. It succeeds the building with platform_led function calling. Thus, it seems the problem is with C++ call the C platform library: ti.platform.evm6678l.ae66 even though the library path is correctly set.

I don't know how  to solve this problem.

Thanks, 

  • The problem is that the file bigtime.cpp includes platform.h (directly or indirectly) outside an 'extern "C"' declaration.

    You need to make sure that every file which includes platform.h is either a C file or includes platform.h inside an 'extern "C"' declaration.

    extern "C" {
    #include "platform.h"
    }
  • Thank you very much. After I change the include to the internal of extern "C" block, it has new errors:

    ...........

    undefined first referenced

    symbol in file

    --------- ----------------

    Osal_platformFree C:/ti/pdk_C6678_1_1_2_5/packages/ti/platform/evmc6678l/platform_lib/lib/debug/ti.platform.evm6678l.ae66<platform.obj>

    Osal_platformMalloc C:/ti/pdk_C6678_1_1_2_5/packages/ti/platform/evmc6678l/platform_lib/lib/debug/ti.platform.evm6678l.ae66<platform.obj>

    Osal_platformSpiCsEnter C:/ti/pdk_C6678_1_1_2_5/packages/ti/platform/evmc6678l/platform_lib/lib/debug/ti.platform.evm6678l.ae66<evmc66x_spi.obj>

    Osal_platformSpiCsExit C:/ti/pdk_C6678_1_1_2_5/packages/ti/platform/evmc6678l/platform_lib/lib/debug/ti.platform.evm6678l.ae66<evmc66x_spi.obj>

    ti_sysbios_BIOS_start__E ./bigtime.obj

    ti_sysbios_family_c64p_TimestampProvider_Module_startup__F C:\Users\Jef\workspace_v5_1_C6678\big_time_LED\Debug\configPkg\package\cfg\bigtime_pe66.oe66

    >> Compilation failure

    error #10234-D: unresolved symbols remain

    error #10010: errors encountered during linking; "big_time_LED.out" not built

    gmake: *** [big_time_LED.out] Error 1

    gmake: Target `all' not remade because of errors.

    **** Build Finished ****

    ......................

    It seems they are internal function/variables related. What is you opinion? Thanks again. I attach the project for your conveneience.5672.big_time_LED.zip

  • You need to do the same thing with all of the SYSBIOS header files.  Everywhere they are included, they need to be included under an 'extern "C"'

  • I have thought as you mentioned in your first reply. The problem is that I do not know what header file I have to insert to the extern clause for symbols:

    Osal_platformFree,

    Osal_platformMalloc

    Osal_platformSpiCsEnter

    Osal_platformSpiCsExit

    I have founded Osal_platformFree is used in platform.c, but there is no definition there. There is only one include line:

    #include "platform_internal.h"

    I do not find Osal_platformFree in the above header file. I do not know how to continue.

    Regards,

  •  

    I forgot to add that the error of "Osal_platformFree" unsolvable is after I have added the platform_internal.h to the include line:

    extern "C" {

    void clockIdle(void);

    #include "ti\platform\evmc6678l\platform_lib\include\platform_internal.h"

    #include "ti\platform\platform.h"

    #include "ti\platform\resource_mgr.h"

    Platform_STATUS platform_led(uint32_t led_id, PLATFORM_LED_OP operation, LED_CLASS_E led_class);

    Platform_STATUS platform_delay(uint32_t usecs);

    }

    .........

    So, how to make the compiler knows Osal_platformFree? Thanks,

  • I suspect platform.h is not intended to be compiled for C++.  If it were, it would contain the extern "C" linkage declaration as described near the end of this wiki article.  But it doesn't. We compiler experts are not familiar with how platform.h and related files are to be used.  I suggest you try the BIOS forum.

    Thanks and regards,

    -George

  • I don't mean to bump an old topic, but I spent quite a while struggling with this one, and only just recently found this thread. There were several threads that I found that had the link to the wiki page for inclusion and linking, but there was really nowhere that mentioned the need to extern "C" { } inclusions for the headers of C libraries.

    I have been working on a sys/bios project in C++ and have been trying to use all sorts of libraries, but no matter what I did, I could simply not successfully compile my application because it would fail at the linking process with "Unresolved external symbol (some function from one of the libraries)". I tried including the header and source of the projects directly, I correctly referenced the .lib file, and went by the books with everything. It wasn't until I found this post that I was finally able to resolve this problem. Perhaps you could add a small section to the wiki page that warns users about the necessity of extern "C"ing any C library headers that they include so they won't have to endure the frustration that I have, haha. I wish I could mark this thread as answered and verify the TI employee response, but it is not mine to do so.

    At any rate, I just want to say thanks for the solution.

    Cheers,
    Charles