Trouble configuring project for BME 688 sensor and nrf52840

SDK version - v2.7.0

Project repository

Hi! I am a junior embedded systems software developer, and I just started working with Nordic's environment. This is my first time using an external library, and I’m having trouble with the BME68X sensor.

I began by creating a new application by copying the "BME68X Sensor Sample" and quickly realized that I needed to download the external library separately, which I did.

I proceeded to download the BME68X library and placed the relevant files in the location shown at the end of this post (see the CMakeLists.txt content). I also downloaded the BSEC static library. Then I built the project to check for any errors, and I encountered the following:


-- Configuring done
-- Generating done
-- Build files have been written to: /Users/emericopedrazagomez/Documents/zephyr/bme68x_iaq/build
-- west build: building application
ninja: error: '/opt/nordic/ncs/v2.7.0/modules/lib/bsec/src/cortex-m4/fpv4-sp-d16-hard/libalgobsec.a', needed by 'zephyr/zephyr_pre0.elf', missing and no known rule to make it
FATAL ERROR: command exited with status 1: /opt/nordic/ncs/toolchains/f8037e9b83/bin/cmake --build /Users/emericopedrazagomez/Documents/zephyr/bme68x_iaq/build


I don’t fully understand how to include external pre-compiled libraries yet. Based on this example, it seems that I just need to add the location of the .a file and the directory of the other files using the library. So I added the following lines to my CMakeLists.txt:

add_library(mylibalgobsec STATIC IMPORTED GLOBAL)
set_target_properties(mylibalgobsec PROPERTIES IMPORTED_LOCATION {$LIB_DIR}/BSEC/algo/bsec_IAQ/bin/gcc/Cortex_M4/libalgobsec.a)
set_target_properties(mylibalgobsec PROPERTIES INTERFACE_INCLUDE_DIRECTORIES /opt/nordic/ncs/v2.7.0/modules/lib/bme68x/src/bme68x)
target_link_libraries(app PUBLIC mylibalgobsec)

However, I’m still getting the same error when building the application. Why do I need to use the location shown in the error?

I tried moving the files to that location, which resulted in different errors, but I’d like to understand what I’m doing wrong here first.

I apologize if this question seems basic—any help would be appreciated!

  • If I added the "libalgobsec.a" file to the location shown on the error message, but I still get this linking errors:

    -- Configuring done
    -- Generating done
    -- Build files have been written to: /Users/emericopedrazagomez/Documents/zephyr/bme68x_iaq/build
    [1/188] Preparing syscall dependency handling
    
    [6/188] Generating include/generated/version.h
    -- Zephyr version: 3.6.99 (/opt/nordic/ncs/v2.7.0/zephyr), build: v3.6.99-ncs2
    [183/188] Linking C executable zephyr/zephyr_pre0.elf
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /Users/emericopedrazagomez/Documents/zephyr/bme68x_iaq/build/zephyr/zephyr_pre0.map 
    : && ccache /opt/nordic/ncs/toolchains/f8037e9b83/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc  -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf  zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj  -fuse-ld=bfd  -T  zephyr/linker_zephyr_pre0.cmd  -Wl,-Map=/Users/emericopedrazagomez/Documents/zephyr/bme68x_iaq/build/zephyr/zephyr_pre0.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/arm/core/libarch__arm__core.a  zephyr/arch/arch/arm/core/cortex_m/libarch__arm__core__cortex_m.a  zephyr/arch/arch/arm/core/mpu/libarch__arm__core__mpu.a  zephyr/lib/libc/picolibc/liblib__libc__picolibc.a  zephyr/lib/libc/common/liblib__libc__common.a  zephyr/soc/soc/nrf52840/libsoc__nordic.a  zephyr/drivers/clock_control/libdrivers__clock_control.a  zephyr/drivers/console/libdrivers__console.a  zephyr/drivers/flash/libdrivers__flash.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/i2c/libdrivers__i2c.a  zephyr/drivers/pinctrl/libdrivers__pinctrl.a  zephyr/drivers/sensor/nordic/temp/libdrivers__sensor__nordic__temp.a  zephyr/drivers/serial/libdrivers__serial.a  zephyr/drivers/timer/libdrivers__timer.a  modules/nrf/drivers/sensor/bme68x_iaq/lib..__nrf__drivers__sensor__bme68x_iaq.a  /opt/nordic/ncs/v2.7.0/zephyr/../modules/lib/bsec/src/cortex-m4/fpv4-sp-d16-hard/libalgobsec.a  modules/nrf/drivers/hw_cc3xx/lib..__nrf__drivers__hw_cc3xx.a  modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a  modules/segger/libmodules__segger.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  -L"/opt/nordic/ncs/toolchains/f8037e9b83/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v7e-m+fp/hard"  -L/Users/emericopedrazagomez/Documents/zephyr/bme68x_iaq/build/zephyr  -lgcc  -lmylibalgobsec  zephyr/arch/common/libisr_tables.a  -mcpu=cortex-m4  -mthumb  -mabi=aapcs  -mfpu=fpv4-sp-d16  -mfloat-abi=hard  -mfp16-format=ieee  -mtp=soft  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn  -Wl,-no-pie  -DPICOLIBC_DOUBLE_PRINTF_SCANF  /opt/nordic/ncs/v2.7.0/nrfxlib/crypto/nrf_cc310_platform/lib/cortex-m4/hard-float/no-interrupts/libnrf_cc310_platform_0.9.19.a  --specs=picolibc.specs  -lc  -lgcc && cd /Users/emericopedrazagomez/Documents/zephyr/bme68x_iaq/build/zephyr && /opt/nordic/ncs/toolchains/f8037e9b83/Cellar/cmake/3.21.0/bin/cmake -E true
    /opt/nordic/ncs/toolchains/f8037e9b83/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd:/opt/nordic/ncs/v2.7.0/zephyr/../modules/lib/bsec/src/cortex-m4/fpv4-sp-d16-hard/libalgobsec.a: file format not recognized; treating as linker script
    /opt/nordic/ncs/toolchains/f8037e9b83/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd:/opt/nordic/ncs/v2.7.0/zephyr/../modules/lib/bsec/src/cortex-m4/fpv4-sp-d16-hard/libalgobsec.a:0: syntax error
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: /opt/nordic/ncs/toolchains/f8037e9b83/bin/cmake --build /Users/emericopedrazagomez/Documents/zephyr/bme68x_iaq/build

    I believe this has to do with the compilated library's format, but I do not know how. 

  • I have not encountered this before but make sure you are using correct Cortex_M4 variant of libalgobsec.a that matches the floating-point configuration (hard vs. soft). For Cortex-M4 with hard float, ensure the path aligns with:

    /path/to/bsec_IAQ/bin/gcc/Cortex_M4/libalgobsec.a.

    Verify that the library was built with a compatible GCC version, it is possible that it is built with incompatible gcc version than the one this toolchain is using.

  • Hi Susheel Nuguru, I appreciate your time and response.

    I double checked and I am indeed using the variant of libalgobsec.a located in /path/to/bsec_IAQ/bin/gcc/Cortex_M4/libalgobsec.a.

    Could you please advise on how to compare the GCC version used to compile this library with the one my toolchain is using? I apologize if this is a very basic question, but I want to ensure compatibility.

  • Try reading the gcc version of the library

    readelf -p .comment /path/to/libalgobsec.a
    

    then do

    ncs/toolchain/ce3b5ff664/bin/arm-none-eabi-gcc --version

    you can see if those versions are compatible.

    Also use readelf to inspect the .ARM.attributes section of the library:

    readelf -A /path/to/libalgobsec.a

    Look for entries like Tag_CPU_name: "Cortex-M4" and Tag_ABI_VFP_args: VFP registers. If you see Tag_ABI_VFP_args: None, the library uses soft float, and it will be incompatible with hard-float configurations.

  • Hi Susheel, thanks again for your reply. 

    I am not sure why the file you mention (arm-none-eabi-gcc) is not in my /bin directory. This is the content of the folder when I run:

    ls ncs/toolchains/f8037e9b83/bin/

    For the installation, I followed these steps from the Nordic Developer Academy course.

    I tried downloading the Zephyr SDK bundle for macos, since It has the arm-none-eabi-gcc file you mention, but I am not exactly sure what to do with it.

Related