Linking BSEC library to ESP-IDF for BME680

apurva
Posts: 6
Joined: Tue Oct 08, 2019 2:47 pm

Linking BSEC library to ESP-IDF for BME680

Postby apurva » Tue Oct 08, 2019 2:50 pm

I am using the BME680 with the ESP32-PoE and I want to use the BSEC library to get the IAQ. I have been stuck at the last step of linking the pre-built libalgobsec.a library. This is what my CMakeLists file in my BSEC components folder looks like:

Code: Select all

set(COMPONENT_SRCS "src/bme680.c"
"src/bsec_integration.c")

set(COMPONENT_ADD_INCLUDEDIRS "include")

register_component()

add_library(algobsec STATIC IMPORTED)
set_property(TARGET algobsec PROPERTY IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/components/BSEC/lib/libalgobsec.a)
target_link_libraries(${COMPONENT_TARGET} PUBLIC algobsec)
This gave me an error - FAILED: bme680_test_with_bsec.elf. The CMakeError.log file gives this output:

Code: Select all

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: C:/Users/Apurva/.espressif/tools/xtensa-esp32-elf/1.22.0-80-g6c4433a5-5.2.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-g++.exe 
Build flags: -mlongcalls
Id flags:  

The output was:
1
c:/users/apurva/.espressif/tools/xtensa-esp32-elf/1.22.0-80-g6c4433a5-5.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: cannot find crt1-sim.o: No such file or directory
c:/users/apurva/.espressif/tools/xtensa-esp32-elf/1.22.0-80-g6c4433a5-5.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: cannot find _vectors.o: No such file or directory
c:/users/apurva/.espressif/tools/xtensa-esp32-elf/1.22.0-80-g6c4433a5-5.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: cannot find -lsim
c:/users/apurva/.espressif/tools/xtensa-esp32-elf/1.22.0-80-g6c4433a5-5.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: cannot find -lhandlers-sim
c:/users/apurva/.espressif/tools/xtensa-esp32-elf/1.22.0-80-g6c4433a5-5.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: cannot find -lhal
collect2.exe: error: ld returned 1 exit status

ovonphil
Posts: 4
Joined: Thu Oct 10, 2019 8:56 am

Re: Linking BSEC library to ESP-IDF for BME680

Postby ovonphil » Thu Oct 10, 2019 8:59 am

I'm having the same problem. Did you manage to solve it? My output is reporting undefined references to bsec functions during the linking process.

apurva
Posts: 6
Joined: Tue Oct 08, 2019 2:47 pm

Re: Linking BSEC library to ESP-IDF for BME680

Postby apurva » Thu Oct 10, 2019 2:45 pm

Hello! I managed to fix the issue. I separated the BME680 files from the BSEC files. My BSEC component structure is as follows:

- include (folder)
  1. bsec_datatypes.h
  2. bsec_integration.h
  3. bsec_interface.h
- lib (folder)
  1. libalgobsec.h (normal)
- bsec_integration.c
- CMakeLists.txt
- component.mk

The CMakeLists.txt contains:

Code: Select all

set(COMPONENT_SRCS 
"bsec_integration.c")

set(COMPONENT_ADD_INCLUDEDIRS include)
set(COMPONENT_REQUIRES "BME680")
register_component()
target_link_libraries(${COMPONENT_TARGET} "-L${CMAKE_CURRENT_LIST_DIR}/lib")
target_link_libraries(${COMPONENT_TARGET} algobsec)
The component.mk contains:

Code: Select all

COMPONENT_SRCDIRS := .
COMPONENT_ADD_INCLUDEDIRS := include

LIBS := algobsec

COMPONENT_ADD_LDFLAGS     := -lbt -L $(COMPONENT_PATH)/lib \
                           $(addprefix -l,$(LIBS))
ALL_LIB_FILES := $(patsubst %,$(COMPONENT_PATH)/lib/lib%.a,$(LIBS))
COMPONENT_ADD_LINKER_DEPS := $(ALL_LIB_FILES)
COMPONENT_SUBMODULES += lib
My BME680 component structure is as follows:

- include (folder)
  1. bme680.h
  2. bme680_defs.h
  3. bme680_platforms.h
  4. bme680_types.h
- bme680.c
- bme680_platform.c
- CMakeLists.txt
- component.mk

The CMakeLists.txt contains:

Code: Select all

set(COMPONENT_SRCS "bme680_platform.c"
                   "bme680.c")
set(COMPONENT_ADD_INCLUDEDIRS "include")

register_component()
The component.mk contains:

Code: Select all

COMPONENT_ADD_INCLUDEDIRS := include
Last edited by apurva on Fri Oct 11, 2019 5:28 pm, edited 1 time in total.

ovonphil
Posts: 4
Joined: Thu Oct 10, 2019 8:56 am

Re: Linking BSEC library to ESP-IDF for BME680

Postby ovonphil » Fri Oct 11, 2019 9:52 am

Thank you for taking the time to post these details apurva. I've tried to copy your method, file structure and file contents, but Im still not getting anywhere. Could you tell me what you have in the CMakeLists.txt file in the top level directory of the project? And what is bme680_platform.c? Is that your own layer?

ovonphil
Posts: 4
Joined: Thu Oct 10, 2019 8:56 am

Re: Linking BSEC library to ESP-IDF for BME680

Postby ovonphil » Fri Oct 11, 2019 10:39 am

It's all building but doesn't appear to be linking. The errors are undefined references to the functions in the binary file, e.g. undefined reference to "bsec_set_configuration"...

ovonphil
Posts: 4
Joined: Thu Oct 10, 2019 8:56 am

Re: Linking BSEC library to ESP-IDF for BME680

Postby ovonphil » Fri Oct 11, 2019 12:24 pm

Got it buildng at last. The problem was that I was using the lite version of the library rather than the normal one, so now it builds, but I'm receving all zeroes in the output, so it looks like there is another hurdle to resolve. I know the sensor and my I2C driver are working, because I was previously reading raw values from it in forced mode, without the BSEC layer.

Thanks again for your post apurva - that has helped me to structure the project better, and no doubt get it building!

Who is online

Users browsing this forum: No registered users and 110 guests