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

Why is adding library c file and include directory resulting in linker errors?

Hi! I'm trying to add the nRF drv_timer library to the ble_app_template example project (BLE Peripheral).

I have added the nrf_drv_timer.c file to the project, and the directory ..\..\..\..\..\..\components\drivers_nrf\timer to my Include Paths under Options for Target (magic wand icon) > C/C++ / Include paths.

in right folder hosted at ImgBB

ImgBB
Image in right folder hosted in ImgBB

The file appears under "Manage Project Items:"

manage project items hosted at ImgBB

ImgBB
Image manage project items hosted in ImgBB

I have set TIMER_ENABLED to 1 in sdk_config.h:

Capture hosted at ImgBB

ImgBB
Image Capture in Jonathan Hale's images album

I get the following linker errors:

.\_build\nrf51422_xxac.axf: Error: L6218E: Undefined symbol nrf_drv_timer_enable (referred from main.o).
.\_build\nrf51422_xxac.axf: Error: L6218E: Undefined symbol nrf_drv_timer_extended_compare (referred from main.o).
.\_build\nrf51422_xxac.axf: Error: L6218E: Undefined symbol nrf_drv_timer_init (referred from main.o).

Does adding files to the project require any additional steps? All the other posts on this topic I have read only mention checking the things I have verified above.

  • Hi Jonathan

    Make sure that the TIMER_ENABLED define in sdk_config.h is set to 1, otherwise the code in nrf_drv_timer.c won't be included and you will get linker errors. 

    Best regards
    Torbjørn Øvrebekk

  • Thanks for responding.

    I forgot to mention above, I already changed TIMER_ENABLED to 1 in sdk_config:

    Capture hosted at ImgBB

    ImgBB
    Image Capture in Jonathan Hale's images album

    Yet, I still get the 3 linker errors mentioned above. I have updated my original question to contain this information.

  • Hi Jonathan

    Have you also set one of the TIMERx_ENABLED defines, like TIMER0_ENABLED?

    Best regards
    Torbjørn

  • This did it. Great work, thanks. Does each library's documentation state the required changes to sdk_config somewhere? Then I wouldn't make this kind of mistake again

  • Hi Jonathan

    Sorry for the late reply, this case slipped through the cracks...

    The documentation doesn't list this unfortunately. Since the documentation is generated from the header files it is better at describing individual functions and structs than to provide the bigger picture of using the driver/library in question. 

    Best regards
    Torbjørn

1 2