Linking external .a file into project

I have a customer that wants to provide me with .a file for some confidential algorithm they want to run. I am tasked with implementing this into my firmware.

Using the links below I have been able to compile in the .a file along with its associated header file. I can even use the #include to include the header file. However, when I start to call functions from the header file, the ld.exe returns an undefined reference exception.

My file structure is below, as well as my CMakelists.txt. It appears that I have followed the links and the example for linking an external library perfectly. Can I get some support to what I am missing, or what I should try next?

Thanks

CMakeLists.txt:

# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(hello_world)

target_sources(app PRIVATE src/main.c)

###
set(insight_src_dir   ${CMAKE_CURRENT_SOURCE_DIR}/insight)

set(INSIGHT_LIB_DIR     ${insight_src_dir}/lib)
set(INSIGHT_INCLUDE_DIR ${insight_src_dir}/inc)

add_library(insight_lib STATIC IMPORTED GLOBAL)

set_target_properties(insight_lib PROPERTIES IMPORTED_LOCATION             ${INSIGHT_LIB_DIR}/insight.a)
set_target_properties(insight_lib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${INSIGHT_INCLUDE_DIR})

target_link_libraries(app PUBLIC insight_lib)
###

Here is my folder structure:

hello_world

  > build

  > insight

      - header.h

  > lib

      - library.a

  > src

      - main.c

  - CMakeLists.txt

  - prj.conf

Parents
  • Hello,

    Could you please try to include the library as shown in the edited CMakelists.txt file below and see if you get the same error? There are several ways you can link in pre-compiled libraries with CMake, and I'm not sure why your approach did not work. 

    # SPDX-License-Identifier: Apache-2.0
    
    cmake_minimum_required(VERSION 3.20.0)
    
    set(INSIGHT_LIB_DIR  ${CMAKE_CURRENT_SOURCE_DIR}/insight)
    
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(hello_world)
    
    target_sources(app PRIVATE src/main.c)
    target_include_directories(app PUBLIC ${INSIGHT_LIB_DIR}/inc)
    
    zephyr_library_link_libraries(${INSIGHT_LIB_DIR}/lib/insight.a)
    

    Here is my folder structure:

    From your CMakelists.txt file it looks like 'lib' and 'inc' folder should be subdirectories in the 'insight' folder?

    Thanks,

    Vidar

Reply
  • Hello,

    Could you please try to include the library as shown in the edited CMakelists.txt file below and see if you get the same error? There are several ways you can link in pre-compiled libraries with CMake, and I'm not sure why your approach did not work. 

    # SPDX-License-Identifier: Apache-2.0
    
    cmake_minimum_required(VERSION 3.20.0)
    
    set(INSIGHT_LIB_DIR  ${CMAKE_CURRENT_SOURCE_DIR}/insight)
    
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(hello_world)
    
    target_sources(app PRIVATE src/main.c)
    target_include_directories(app PUBLIC ${INSIGHT_LIB_DIR}/inc)
    
    zephyr_library_link_libraries(${INSIGHT_LIB_DIR}/lib/insight.a)
    

    Here is my folder structure:

    From your CMakelists.txt file it looks like 'lib' and 'inc' folder should be subdirectories in the 'insight' folder?

    Thanks,

    Vidar

Children
Related