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

Add static library (.a) to project

Hi,

I'm trying to link a static library that provided by others to my own project. I followed the steps in this post (https://devzone.nordicsemi.com/f/nordic-q-a/39338/segger-studio-static-library-adding-to-linker)  but I got the error 'undefined reference' when I try to use the APIs from that library.

I have included the following lines in my CMakeLists:

zephyr_library_include_directories(
  externlib/inc/
  )

add_library(testlib STATIC IMPORTED)
target_link_libraries(app PUBLIC ${APPLICATION_SOURCE_DIR}/externlib/lib/testlib.a)

And my project folder looks like this:

├--- CMakeLists.txt

├--- prj.conf

├--- nrf9160_pca10090ns.overlay

├--- scr

    └-- main.c

└--- externlib

    └-- inc

        └-- testlib.h #header file to be included

    └-- lib

        └-- testlib.a #library to be added

Please can someone let me know if I missed any steps to include the static library correctly?

Thank you

Arno

Parents Reply Children
  • Hi Heidi,

    The error says: .../src/main.c:237: undefined reference to `get_sleep_time'
    1> collect2.exe: error: ld returned 1 exit status

    'get_sleep_time' was the API I tried to used from the static library.

    But I tried to include another library using the same method and it works well, seems like its the problem with this library itself? I will double check, but thank you for shaing the sample.

    Arno

Related