This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

CMake script for add eternal libaray ( BSEC ) to test Bosch sensor raeding?

hello,

i have downloaded    ( BSEC )    library from https://www.bosch-sensortec.com/software-tools/software/bsec/  for read sensor data . now want to test the code by build and flashing it with VS code for thingy 91 borad.

CMamke  file have 

FILE(GLOB bsec_integration src/*.c)

target_sources(app PRIVATE src/bsec_integration.c)
target_sources(app PRIVATE src/bme680.c)

i have add c file and header file in scr folder .

on build shows error 

FATAL ERROR: command exited with status 1: 'c:\Users\mohit\ncs\v1.9.1\toolchain\opt\bin\cmake.EXE' '-DWEST_PYTHON=c:\Users\mohit\ncs\v1.9.1\toolchain\opt\bin\python.exe' '-Be:\Nordic_Acadmey\bsec_integration\build_1' '-Se:\Nordic_Acadmey\bsec_integration' -GNinja -DBOARD=thingy91_nrf9160 -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=On -DNCS_TOOLCHAIN_VERSION:STRING=NONE.

please suggest

Parents
  • Ok, so to add a ".a" library to an NCS project, you need to add the path to the library and it's header files. One way to do it is like this:

    Create this folder structure by creating a new folder called bsec_lib next to your src folder (you can place it anywhere, but I will use this location for demonstration).

    inside the bsec folder, create two folders. One called "inc" and one called "lib".

    In the library folder that you downloaded externally, copy the libalgobsec.a file from BSEC_1.4.8.0_Generic_Release_updated_v3\algo\normal_version\bin\gcc\Cortex_M4\libalgobsec.a into your new "lib" folder, and copy the two .h files from the same folder into your "inc" folder. 

    Now go to your prj.conf file and remove most of your configurations. All you need are these (in order to compile, you may need more later):

    CONFIG_NEWLIB_LIBC=y
    CONFIG_SENSOR=y
    CONFIG_BME680=y
    

    Then open your CMakeLists.txt file to add your library. I did it like this:

    # 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)
    target_sources(app PRIVATE src/bme680.c)
    target_sources(app PRIVATE src/bsec_integration.c)
    target_sources(app PRIVATE src/bsec_serialized_configurations_iaq.c)
    zephyr_library_include_directories(src/)
    
    add_library(my_library STATIC IMPORTED GLOBAL)
    
    set(mylib_src_dir   ${CMAKE_CURRENT_SOURCE_DIR}/bsec_lib)
    
    set(MYLIB_LIB_DIR     ${mylib_src_dir}/lib)
    set(MYLIB_INCLUDE_DIR ${mylib_src_dir}/inc)
    
    set_target_properties(my_library PROPERTIES IMPORTED_LOCATION ${MYLIB_LIB_DIR}/libalgobsec.a)
    set_target_properties(my_library PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${MYLIB_INCLUDE_DIR})
    
    target_link_libraries(app PUBLIC my_library)

    And then it compiled without any errors. 

    Best regards,

    Edvin

Reply
  • Ok, so to add a ".a" library to an NCS project, you need to add the path to the library and it's header files. One way to do it is like this:

    Create this folder structure by creating a new folder called bsec_lib next to your src folder (you can place it anywhere, but I will use this location for demonstration).

    inside the bsec folder, create two folders. One called "inc" and one called "lib".

    In the library folder that you downloaded externally, copy the libalgobsec.a file from BSEC_1.4.8.0_Generic_Release_updated_v3\algo\normal_version\bin\gcc\Cortex_M4\libalgobsec.a into your new "lib" folder, and copy the two .h files from the same folder into your "inc" folder. 

    Now go to your prj.conf file and remove most of your configurations. All you need are these (in order to compile, you may need more later):

    CONFIG_NEWLIB_LIBC=y
    CONFIG_SENSOR=y
    CONFIG_BME680=y
    

    Then open your CMakeLists.txt file to add your library. I did it like this:

    # 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)
    target_sources(app PRIVATE src/bme680.c)
    target_sources(app PRIVATE src/bsec_integration.c)
    target_sources(app PRIVATE src/bsec_serialized_configurations_iaq.c)
    zephyr_library_include_directories(src/)
    
    add_library(my_library STATIC IMPORTED GLOBAL)
    
    set(mylib_src_dir   ${CMAKE_CURRENT_SOURCE_DIR}/bsec_lib)
    
    set(MYLIB_LIB_DIR     ${mylib_src_dir}/lib)
    set(MYLIB_INCLUDE_DIR ${mylib_src_dir}/inc)
    
    set_target_properties(my_library PROPERTIES IMPORTED_LOCATION ${MYLIB_LIB_DIR}/libalgobsec.a)
    set_target_properties(my_library PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${MYLIB_INCLUDE_DIR})
    
    target_link_libraries(app PUBLIC my_library)

    And then it compiled without any errors. 

    Best regards,

    Edvin

Children
Related