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

  • yes Sir, this file is same and i am getting same error.

    That time i have no solution so i using hit and trial method so , error keep changing with my effort . 

    I don't make any changes in rest files , i changed only CMake file script .I you can modify it , my desire is same as in my first post . 

    i also shared CMake file in my old post you can compare it with ZIP i make several changes in only in CMake file. 

  • Ok,

    Can you please upload a project that gives the same error that you said you had initially? The one where it said this:

    c:/users/mohit/nrf/v1.9.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(bsec_integration.c.obj): in function `bme680_bsec_update_subscription':
    C:\Users\mohit\nrf\v1.9.1\Nordic_Acadmey\bsec\src\bsec_integration.c:140: undefined reference to `bsec_update_subscription'
    c:/users/mohit/nrf/v1.9.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(bsec_integration.c.obj): in function `bme680_bsec_process_data':
    C:\Users\mohit\nrf\v1.9.1\Nordic_Acadmey\bsec\src\bsec_integration.c:417: undefined reference to `bsec_do_steps'
    c:/users/mohit/nrf/v1.9.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(bsec_integration.c.obj): in function `bsec_iot_init':
    C:\Users\mohit\nrf\v1.9.1\Nordic_Acadmey\bsec\src\bsec_integration.c:186: undefined reference to `bsec_init'
    c:/users/mohit/nrf/v1.9.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\mohit\nrf\v1.9.1\Nordic_Acadmey\bsec\src\bsec_integration.c:207: undefined reference to `bsec_set_state'
    c:/users/mohit/nrf/v1.9.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\mohit\nrf\v1.9.1\Nordic_Acadmey\bsec\src\bsec_integration.c:196: undefined reference to `bsec_set_configuration'
    c:/users/mohit/nrf/v1.9.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(bsec_integration.c.obj): in function `bsec_iot_loop':
    C:\Users\mohit\nrf\v1.9.1\Nordic_Acadmey\bsec\src\bsec_integration.c:539: undefined reference to `bsec_get_state'
    c:/users/mohit/nrf/v1.9.1/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\mohit\nrf\v1.9.1\Nordic_Acadmey\bsec\src\bsec_integration.c:521: undefined reference to `bsec_sensor_control'

  • than you sir for prompt reply , As I already explained i con't create same error , I have shared all file i am working on . 

    my goal is clear i want to build my project file as share as zip , i am ready to do modification in all file as you want but i don't want to change main.c file .

    my question is same 

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

    i already shared BSEC file Library download link and downloaded zip file as well .

    you can ignore all file except main.c file . 

    1. Bme860 and adxl362 both sensor are supported by nordic ,

    if you resolve my one problem rest problem resolve automatically .

    2. i learn how to add any header file for any project , but this is not sufficient for achieve my goal ,if you have download bsec_1-4-8-0_generic_release_updated_v3.zip  file as i share in previous post you can see there was 

    a folder "config"  which contain c file and header files , i don't know how to provide path to tis folder 

    3. i want to make a project file by which i can compile main.c file (as shared in zip name"bsec").

      

  • 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

  • thank you sir , i have done as you suggested  but i got this error. (in attached image )

    Please find the attached zip file , attached file is modified as you suggest .

    6685.bsec.rar

    thank you very much for the valuable support  . 

Related