Search code examples
arduinoesp32arduino-ide

Issues with BSEC Library Arduino


I just want to get the library working in Arduino IDE 1.8.13. However, it always fails to compile. I have adjusted the platform.txt, however it did not do anything. I have downloaded the library from github (https://github.com/BoschSensortec/BSEC-Arduino-library). It always comes back the same error when compiling with the ESP32 board. Where is my mistake?

Here is the debug code:

libraries/BSEC_Software_Library/BSEC_Software_Library.a(bsec.cpp.o):(.literal._ZN4Bsec11beginCommonEv+0x4): undefined reference to `bsec_init'
libraries/BSEC_Software_Library/BSEC_Software_Library.a(bsec.cpp.o):(.literal._ZN4Bsec11beginCommonEv+0x8): undefined reference to `bsec_get_version'
libraries/BSEC_Software_Library/BSEC_Software_Library.a(bsec.cpp.o):(.literal._ZN4Bsec18updateSubscriptionEP21bsec_virtual_sensor_thf+0x0): undefined reference to `bsec_update_subscription'
libraries/BSEC_Software_Library/BSEC_Software_Library.a(bsec.cpp.o):(.literal._ZN4Bsec8setStateEPh+0x10): undefined reference to `bsec_set_state'
libraries/BSEC_Software_Library/BSEC_Software_Library.a(bsec.cpp.o):(.literal._ZN4Bsec15readProcessDataEx19bsec_bme_settings_t+0x14): undefined reference to `bsec_do_steps'
libraries/BSEC_Software_Library/BSEC_Software_Library.a(bsec.cpp.o):(.literal._ZN4Bsec3runEx+0x0): undefined reference to `bsec_sensor_control'
libraries/BSEC_Software_Library/BSEC_Software_Library.a(bsec.cpp.o):(.literal._ZN4Bsec3runEx+0x4): undefined reference to `bsec_get_state'
libraries/BSEC_Software_Library/BSEC_Software_Library.a(bsec.cpp.o): In function `Bsec::beginCommon()':
/Users/Service/Documents/Arduino/libraries/BSEC_Software_Library/src/bsec.cpp:476: undefined reference to `bsec_init'
libraries/BSEC_Software_Library/BSEC_Software_Library.a(bsec.cpp.o): In function `Bsec::getVersion()':
/Users/Service/Documents/Arduino/libraries/BSEC_Software_Library/src/bsec.cpp:476: undefined reference to `bsec_get_version'
libraries/BSEC_Software_Library/BSEC_Software_Library.a(bsec.cpp.o): In function `Bsec::updateSubscription(bsec_virtual_sensor_t*, unsigned char, float)':
/Users/Service/Documents/Arduino/libraries/BSEC_Software_Library/src/bsec.cpp:476: undefined reference to `bsec_update_subscription'
libraries/BSEC_Software_Library/BSEC_Software_Library.a(bsec.cpp.o): In function `Bsec::setState(unsigned char*)':
/Users/Service/Documents/Arduino/libraries/BSEC_Software_Library/src/bsec.cpp:476: undefined reference to `bsec_set_state'
libraries/BSEC_Software_Library/BSEC_Software_Library.a(bsec.cpp.o): In function `Bsec::readProcessData(long long, bsec_bme_settings_t)':
/Users/Service/Documents/Arduino/libraries/BSEC_Software_Library/src/bsec.cpp:385: undefined reference to `bsec_do_steps'
libraries/BSEC_Software_Library/BSEC_Software_Library.a(bsec.cpp.o): In function `Bsec::run(long long)':
/Users/Service/Documents/Arduino/libraries/BSEC_Software_Library/src/bsec.cpp:200: undefined reference to `bsec_init'
/Users/Service/Documents/Arduino/libraries/BSEC_Software_Library/src/bsec.cpp:210: undefined reference to `bsec_update_subscription'
/Users/Service/Documents/Arduino/libraries/BSEC_Software_Library/src/bsec.cpp:210: undefined reference to `bsec_sensor_control'
/Users/Service/Documents/Arduino/libraries/BSEC_Software_Library/src/bsec.cpp:246: undefined reference to `bsec_get_state'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board DOIT ESP32 DEVKIT V1.

Thank you


Solution

  • The Arduino IDE 1.8.13 will find the library if you make the correct modification to the platform.txt file. My file is located here:

    C:\Users\(username)\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\platform.txt
    

    First make sure the general change is in your platform.txt file. That is, you have compiler.libraries.ldflags defined. My platform.txt already had it defined as empty, compiler.libraries.ldflags=. If yours is not already defined, then add that line somewhere in your platform.txt file.

    Next, you want to reference it. You can follow the instructions given for ESP8266. Change the following:

    recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {compiler.libraries.ldflags} -Wl,--start-group {object_files} "{archive_file_path}" {compiler.c.elf.libs} {build.extra_libs} -Wl,--end-group -Wl,-EL -o "{build.path}/{build.project_name}.elf"

    To this:

    recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {compiler.libraries.ldflags} -Wl,--start-group {object_files} "{archive_file_path}" {compiler.c.elf.libs} {compiler.libraries.ldflags} {build.extra_libs} -Wl,--end-group -Wl,-EL -o "{build.path}/{build.project_name}.elf"

    Note the last occurrence of compiler.libraries.ldflags. My text shown above does not match the text shown in the github document exactly. I simply added the compiler.libraries.ldflags after the --start-group directive, which is what the github doc shows.

    Once I did this, saved the file, and restarted Arduino, it all compiled and linked successfully.