How to link libraries


i am new to platformio and i struggle with linking libraries in my project. My first goal is, that i can compile the following minimal example.

#include <Arduino.h>
#include <pbc.h>

void setup() {}
void loop() {}

That pbc.h can be found i added in the platformio.ini a line with build flags:

platform = espressif8266
board = nodemcuv2
framework = arduino
build_flags= -I ~/.local/include/pbc -L ~/.local/lib -Wl,-rpath ~/.local/lib -l pbc -lgmp

When i try to compile it, i got the following error message:

> Executing task in folder pbcTest: platformio run <

Processing nodemcuv2 (platform: espressif8266; board: nodemcuv2; framework: arduino)
Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Espressif 8266 2.5.1 > NodeMCU 1.0 (ESP-12E Module)
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
 - framework-arduinoespressif8266 3.20701.0 (2.7.1) 
 - tool-esptool 1.413.0 (4.13) 
 - tool-esptoolpy 1.20800.0 (2.8.0) 
 - toolchain-xtensa 2.40802.200502 (4.8.2)
LDF: Library Dependency Finder ->
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 29 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
*** [.pio/build/nodemcuv2/firmware.elf] TypeError `Tried to lookup File '/home/thomas/.platformio/platforms/espressif8266/builder/~/.local/lib' as a Dir.' trying to evaluate `${_concat(LIBDIRPREFIX, LIBPATH, LIBDIRSUFFIX, __env__, RDirs, TARGET, SOURCE)}'
============================= [FAILED] Took 1.15 seconds =============================
The terminal process terminated with exit code: 1

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

Reading the error message, i think the programm looks in the wrong directory for the needed libraries. It should look in ~/.local/include and ~/.local/lib but i think it looks in /home/thomas/.platformio/platforms/espressif8266/builder/~/.local/lib .

How can i achieve it, that the compiler looks in the right directory for the needed libraries?

Maybe as additional information: I am using Linux and when i compile a test file with gcc test.c -I ~/.local/include/pbc -L ~/.local/lib -Wl,-rpath ~/.local/lib -l pbc -lgmp everything works fine.

Have you tried using full paths instead of ~ abbreviation?

The build command you are using looks as if you are trying the build a software using globally installed header and library files (even though it refers to a user directory called .local). This is a Unix style approach for building software that will run on the same architecture as it was built.

However, you are probably running on some x88_64 system and building for ESP8266. Do you really have ESP8266 specific header files and binary library files in ~/.local?

I’ve never seen such an approach for the ESP8266 and for the Arduino framework. It might be a misunderstanding about how MCU development is done. If so, provide more information about what you really want to do.