Error on link process - cannot find -lalgobsec

Hi,

During the linkedit process, I am receive “cannot find -lalgobsec” and this is true because I don´t have this library. I have a bsec.h, a Bosh Environment Sensor. I don´t know if I have to include or delete something :slight_smile:

Could you help me?

Below I dropped the PlatformIO.ini and the compilation/linkedit messages

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:wiscore_rak4631]
platform = nordicnrf52
board = wiscore_rak4631
framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries
; build_flags = 
lib_deps = 
    SX126X-Arduino
    BSEC Software Library
    ArduinoModbus
    closedcube/ClosedCube OPT3001@^1.1.2
upload_port = COM[17]
upload_speed = 115200
[platformio]
description = RAK1906 - temp.-hum-press-airq, RAK1903 light, RS485 modbus, LoRaWAN
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf52/wiscore_rak4631.html
PLATFORM: Nordic nRF52 (6.0.0) > WisCore RAK4631 Board
HARDWARE: NRF52840 64MHz, 243KB RAM, 796KB Flash
DEBUG: Current (jlink) External (jlink, stlink)
PACKAGES:
 - framework-arduinoadafruitnrf52 1.2100.201028 (21.0)
 - tool-sreccat 1.164.0 (1.64)
 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 16 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <SX126x-Arduino> 1.2.1
|   |-- <SPI> 1.0
|-- <BSEC Software Library> 1.6.1480
|   |-- <SPI> 1.0
|   |-- <Wire> 1.0
|-- <ArduinoModbus> 1.0.3
|   |-- <ArduinoRS485> 1.0.0
|-- <ClosedCube OPT3001> 1.1.2
|   |-- <Wire> 1.0
|-- <ArduinoRS485> 1.0.0
|-- <SPI> 1.0
Building in release mode
Linking .pio\build\wiscore_rak4631\firmware.elf
c:/users/claudio rosa/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find **-lalgobsec**
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\wiscore_rak4631\firmware.elf] Error 1
================================================================= [FAILED] Took 6.56 seconds =================================================================
The terminal process "C:\Users\Claudio Rosa\.platformio\penv\Scripts\pio.exe 'run'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.
1 Like

The library might be misconfigured and doesn’t do a -L <path to the folder where the libalgobsec.a is> flag. Can you manually do that with build_flags and retry? Note that there might be several folders for different MCU architectures and you need to pick the right one.

Hum… Let me try…

Perfect: Thank you very much! :slight_smile:

[env:wiscore_rak4631]
platform = nordicnrf52
board = wiscore_rak4631
framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries
build_flags = -L libalgobsec.a
lib_deps = 
    SX126X-Arduino
    ArduinoModbus
    closedcube/ClosedCube OPT3001@^1.1.2
    boschsensortec/BSEC Software Library@^1.6.1480
upload_port = COM[17]
upload_speed = 115200
[platformio]
description = RAK1906 - temp.-hum-press-airq, RAK1903 light, RS485 modbus, LoRaWAN

Ehm that can’t be right. The -L argument must be a path to a folder, not a file. Also your screenshot is showing that a project clean goes through, but not a build. I’ve tested this and it doesn’t work.

This board is not contained platform-nordicnrf52/boards at develop · platformio/platform-nordicnrf52 · GitHub so I think it’s custom. So I don’t know CPU type it is. Usually the nRF52 chips are Cortex-M4 cores though.

I’ve tested a minimal example with the adafruit_feather_nrf52832 board and found out needs the library for Cortex-M4 in the fpv4-sp-d16-hard variant. What is working for is when I do

[env:adafruit_feather_nrf52832]
platform = nordicnrf52
board = adafruit_feather_nrf52832
framework = arduino
lib_deps =
     boschsensortec/BSEC Software Library @ ^1.6.1480
; valid for cortex-m4 cores compiled with hard floating point option. 
; environment name needs to be adapted if used in a different platformio.ini
build_flags = -L".pio/libdeps/adafruit_feather_nrf52832/BSEC Software Library/src/cortex-m4/fpv4-sp-d16-hard"

So I out a -L option and then the path where the library would be, in the internal libdeps folder for the name of my environment, adafruit_feather_nrf52832.

Please double check whethe you can really build.

PS: The fundamental problem is though that the library extracts the wrong information to deduce the include path

Here, BOARD_MCU is e.g. for my adafruit_feather_nrf52832 the value

and not what the library expects which has a cortex-m4 folder. That would be in

Let me check again. Just a minute

Now I remenber that Bernd, in the RAKWireless Forum, told me that we have a problem in the Bosch Library. I already fixed in the Board.txt config Arduino file.

Now I will need to do a similar thing here:

Bernd told me:
"Bosch BSEC library changed in November 2020.
In order to get it compiled for WisBlock you need to change one line in the RAK BSP.

Please locate the file boards.txt inside the RAK BSP. On Windows the path is:
C:\Users*>USERNAME<*\AppData\Local\Arduino15\packages\raknrf\hardware\nrf52\0.21.1
>USERNAME< should be replaced with your username.

Open boards.txt with a text editor (notepad or similar, NOT WORD) and look for this line:
WisCoreRAK4631Board.build.mcu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
it should be line 38.
Change the line to:
WisCoreRAK4631Board.build.mcu=cortex-m4
and save the file. Close ArduinoIDE, open it again and try to compile the example again.

I am sorry for the inconvenience. We are in the process to update the BSP and will release a new version soon."

I already submited a Change Request for LIBS=[‘libalgobsec’]

Huh? The previous LIBS=['algobsec'] is correct in the extra script of the library. Since we want to link the file libalgobsec.a, we have to do a -lalgobsec, since the lib prefix is also implied. If the script would do as you suggest, it would end up generating a -llibalgobsec flag, which searches for liblibalgobsec.a, which doesn’t exist. The problem is in the logic generating the LIBPATH, since it doesn’t end up generating the path to where the correct version of libalgobsec.a is stored. Hence why I manually added it with a -L expression. (-L is library search path, -l is the library you want to link).

When you do this you downgrade the compiled binary from hard-float so softfp or even soft floating point implementation, so perfomance is maybe lost. The library already has a hardfloat-compiled version available (next to the softfloat) for Cortex-M4 chips (which I assume is in your WisCoreRAK4631Board) – since I can’t find a reference to that board, google gives only 2 results, one of which is yoru forum post, I can’t verify that), so no change in compiler options for the core would be needed.

But if you did want to apply that to PlatformIO, you would need to build_unflags the old -mfpu and -mfloat-abi flags and build_flags in the new flags.

Let me return the original script to try to explain for you the original link error message. It is below:

[env:wiscore_rak4631]
platform = nordicnrf52
board = wiscore_rak4631
framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries
build_flags = -lalgobsec
lib_deps = 
     SX126X-Arduino
    ArduinoModbus
    closedcube/ClosedCube OPT3001@^1.1.2
    boschsensortec/BSEC Software Library@^1.6.1480
upload_port = COM[17]
upload_speed = 115200
[platformio]
description = RAK1906 - temp.-hum-press-airq, RAK1903 light, RS485 modbus, LoRaWAN

Linking .pio\build\wiscore_rak4631\firmware.elf
c:/users/claudio rosa/.platformio/packages/toolchain-gccarmnoneeabi/bin/…/lib/gcc/arm-none-eabi/7.2.1/…/…/…/…/arm-none-eabi/bin/ld.exe: cannot find -lalgobsec
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\wiscore_rak4631\firmware.elf] Error 1
================================================================= [FAILED] Took 18.08 seconds =================================================================
The terminal process “C:\Users\Claudio Rosa.platformio\penv\Scripts\pio.exe ‘run’” terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

It makes no difference to have this flag or not. There will be the same error without it, since thanks to the extra_script in the BSEC library, algobsec is already added to the libs, thus generating that linker command. What matters is that the -L search path was wrnog.

But okay, I understand you correctly that you’ve found a way to successfully compile / link the library?

No, it isn´t work yet.

I am trying to move from Arduino IDE to PlatformIO IDE, and I already understood the PlatformIO is a powerful tool but I need to configure all requirements for compilation and linkedition and it is not so obvious :smiley:

The lib that I have it is place in a Arduino folder, but I would like to have a clear environment vision, I mean just one IDE working fine well adjusted to be able to do what I need. Make it sense?

Take a look in the path:
F:\Users\Claudio Rosa\Documents\Arduino\libraries\BSEC_Software_Library\src\esp8266\libalgobsec.a
I think that the path for this file is wrong. I would like to have a path for the PlatformIO Libs. I was expecting the parameter “lib_deps =” it should do this job, but it isn´t.

May I am wrong but I think that I have to clean the PlatformIO IDE environment, for example remove any pointer to Arduino IDE environment like this:“lib_extra_dirs = ~/Documents/Arduino/libraries”

Why would you want to use the XTensa ESP8266 version for linking with a nordic-nrf52 type Cortex-M chip?

If you declare all your libraries via lib_deps in the platformio.ini, it should be able to be stand-alone and not need any Arduino IDE installation.

  1. You’re using board = wiscore_rak4631. Where did you get the JSON board definition from?
  2. Does adding
build_flags = -L".pio/libdeps/wiscore_rak4631/BSEC Software Library/src/cortex-m4/fpv4-sp-d16-hard"

to the platformio.ini make a difference? If not, post error message of a build (you previously showed a “Clean”)

This is a RAKWireless WisBLock Board: Installation of Board Support Package in PlatformIO

The answers:
The JSON is one of the things provide in the RAKWirelss Instalation Guide above
I did a cleaning process, I mean I am re-starting from scratch. Take a look in the platformio.ini below.

I think that if I declare some libs in the “lib_deps =”, the effect should be the same that “build_flags =”. Am I wrong?

Blockquote
[env:wiscore_rak4631]
platform = nordicnrf52
board = wiscore_rak4631
framework = arduino
lib_deps =
boschsensortec/BSEC Software Library@^1.6.1480
closedcube/ClosedCube OPT3001@^1.1.2
Blockquote

Just to complement, it is board that you can add modules, I mean, in my case it is: WisBlock

  1. 1 RAK Base : board
  2. 1 RAK Core MCU + LoRa Radio:
  3. 1 RAK1906 - Environment sensors:
  4. 1 RAK1903 - Optical Sensor:

build_flags and lib_deps are two different things. The first will add arbitrary flags into the GCC/G++ invocations. The second will add a library reference (from either local storage of the PIO library registry) to the project and in the build process.

You are right in a sense that adding a library via lib_deps will make it be included in the build and linking process. However, as I’ve explained above, this is a special case. The BSEC library has its functionality in a statically compiled library, libalgobsec.a. To link a static library with GCC, it needs to be given a -l flag followed by the name of the library file without the initial lib and without .a. So we need -lalgobsec here. Further GCC needs to know where that file can be found on the harddisk. For that it needs a -L flag to add a path to the “library search path”. During the linking process, it will search through all given -L flags to try and find the libalgobsec.a here, if we gave it -lalgobsec before.

Depending on which microcontroller and core-type you’re building for, the BSEC library needs to use a different version of the static library (see here). PlatformIO will not blindly link every .a file that it finds in the library’s folder. The library itself is responsible for adding that logic, through the library.json file. There, the BSEC authors did

use a PlatformIO thing called Advanced Scripting. So, this Python script will try and modify some variables in the PlatformIO build process (based on SCons) to make it produce the right -l and -L flag.

And that is where the library script has a bug. That’s what I’m trying to explain to you since 5 posts.

The line LIBS=['algobsec'] is correct, this will cause SCons to emit -lalgobsec. But it screws up the LIBPATH that will end up generating the -L flag. From the structure of the library as linked above, we know that we need the file in src/cortex-m4/fpv4-sp-d16-hard because that is the CPU type and the FPU flags we are compiling with when using the wiscore_rak4631 board.

However, the script can impossible generate the correct path with the expression realpath(join('src', env.get('BOARD_MCU'))). BOARD_MCU will evaluate to

https://github.com/RAKWireless/WisBlock/blob/master/PlatformIO/wiscore_rak4631.json#L29-L29

So it will end up generating -L src/nrf52840. And that folder simply doesn’t exist in the BSEC library and is the wrong path.

Thus we have to correct the script bug in the BSEC library by injecting the correct -L flag so that the correct library file is found.

Please test the following. In a blank project, use the platformio.ini

[env:wiscore_rak4631]
platform = nordicnrf52
board = wiscore_rak4631 
framework = arduino
lib_deps =
     boschsensortec/BSEC Software Library @ ^1.6.1480
; valid for cortex-m4 cores compiled with hard floating point option. 
; environment name needs to be adapted if used in a different platformio.ini
build_flags = -L".pio/libdeps/wiscore_rak4631/BSEC Software Library/src/cortex-m4/fpv4-sp-d16-hard"

and fill the src\main.cpp from BSEC-Arduino-library/examples/basic/basic.ino at 7a9357566c75048331c15b55a4eb20f1de14f36e · boschsensortec/BSEC-Arduino-library · GitHub, but add the line #include <Arduino.h> as the first line.

Build the project. You’ll see…

It builds.

Now as I said you usually don’t have to touch the build flags to correctly use a library, but the library (script) simply has a bug there because it doesn’t expect to be included from such a board where the mcu value is not cortex-m4, and it also doesn’t respect the hardfloat options.

Of course it would be nice to get that bug fixed, but…

they don’t even accept issues. No tab for it. A nice way to have 0 bug reports.

1 Like

I will try now. As soon as possible I will send news…

1 Like

Hu!!! :sweat_smile:

IT IS WORKING :upside_down_face:

Thank you very much!

Have a good night!

Blockquote

[env:wiscore_rak4631]
platform = nordicnrf52
board = wiscore_rak4631
framework = arduino
lib_deps =
SX126X-Arduino
ArduinoModbus
closedcube/ClosedCube OPT3001@^1.1.2
boschsensortec/BSEC Software Library @ ^1.6.1480
; valid for cortex-m4 cores compiled with hard floating point option.
; environment name needs to be adapted if used in a different platformio.ini
build_flags = -L".pio/libdeps/wiscore_rak4631/BSEC Software Library/src/cortex-m4/fpv4-sp-d16-hard"
upload_port = COM[17]
upload_speed = 115200
[platformio]
description = RAK1906 - temp.-hum-press-airq, RAK1903 light, RS485 modbus, LoRaWAN

Blockquote

2 Likes

Thank you! This solution just helped me get around the same problem with the BSEC Software Library!
Adding the build_flags=-L"…" as described above to my platforio.ini file fixed the problem right away. Because of all your support last year, it saved me hours of debugging today - just a simple search and I found the answer.

Thank you again!
Kim