This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

linker issue, undefined reference

Hi,

just start with SEGGER Embedded and use a usb acm to setup my target

to have a clean structure I moved code from main.c to dedicated files have the USB and BSP

I create new folder in the SEGGER and add the new files. They get compiled and no warnings
But the link failed

3> Compiling 'bsphandler.c'
4> Compiling 'usbhandler.c'

1> /usr/share/segger_embedded_studio_for_arm_5.20/gcc/arm-none-eabi/bin/
ld: Output/Debug/Obj/nRFGeofence_pca10056/main.o:(.rodata.m_app_cdc_acm+0x1c):
undefined reference to `cdc_acm_user_ev_handler'
1> /usr/share/segger_embedded_studio_for_arm_5.20/gcc/arm-none-eabi/bin/ld: Output/Debug/Obj/nRFGeofence_pca10056/main.o: in function `init_cli':
1> /home/chris/devel/RF52/nRF5_SDK_17.0.2_d674dde/examples/gtsys/nRFGeofence/main.c:91: undefined reference to `bsp_event_callback'
1> /usr/share/segger_embedded_studio_for_arm_5.20/gcc/arm-none-eabi/bin/ld: Output/Debug/Obj/nRFGeofence_pca10056/main.o: in function `main':
1> /home/chris/devel/RF52/nRF5_SDK_17.0.2_d674dde/examples/gtsys/nRFGeofence/main.c:117: undefined reference to `init_bsp'
1> /usr/share/segger_embedded_studio_for_arm_5.20/gcc/arm-none-eabi/bin/ld: Output/Debug/Obj/nRFGeofence_pca10056/main.o:(.rodata.usbd_config.15191+0x4): undefined reference to `usbd_user_ev_handler'

the static functions for cdc_acm_user_ev_handler move from main.c to usbhandler.c

Where is the hint? Why does the linker hasn't usbhandler.o used?

I running the development on a x64 Linux machine, no! I do not have Windows.

Some helpful tips needed.

Regards
Chris

  • Hi Chris

    Where do you define the cdc_acm_user_ev_handler() function in your application. Seeing as you moved it from main.c to a dedicated file, you likely have to include the file defining cdc_acm_user_ev_handler() to this dedicated file. I assume the following errors you're seeing are consequential errors.

    Best regards,

    Simon

  • Hi Simon,

    I used the SEGGER native method to add new files,
    1st) add a Folder 'Implementation'
    2nd) add new files to the folder bsphandler.c usbhandler.c
    3rd) move static functions from main.c to bsphander.c & usbhandler.c add the definitions to header files
    bsphandler.h & usbhandler.h  and use #include directive in main to make them
    available for the Compile process.

    Both objects are in the projects output directory. (xxxhandler.o)

    My missing link is, where to add so that the linker will use them in the SEGGER Embedded environment.
    They got compiled but the linker does not inherit them.

    -Chris

  • Hi Simon,

    I found the solution meanwhile. If I move the functions out the the main.c they can't be static any more.
    Change the definitions to a non-static function make the trick!
    Same with global static variables which I will move to there modules now.

    Regards

    Chris 

Related