Pre-compiled static libraries


I wanted to know if it is possible to use some pre-compiled static libraries and related header files and reference them in a code which is in src directory.


Please take a look at build_flags.

build_flags = -I/opt/include -L/opt/lib -lfoo

Ahh…thanks, I almost forgot about it.

So I have library someLib.a, that I would like to use in my project. Will be my command look like:
build_flags = -L/folderToLibrary -lsomeLib


Yes, you are right. You need 2 things:

  • add a path where mylib.a archive is located via -L ...
  • add extra path to CPPATH where are located headers files via -I ...
  • add precompiled library to linker via -l mylib.

Hello, I can’t get this to work, can you help?

In the project directory structure I’ve add the .h file to the include folder and the library .a file to the lib folder, so:



and in the platformio.ini file I add:

build_flags = -L/lib -lquarklink-client -I/include

and get a build error:

Indexing .pio\build\esp32_idf_test\bootloader\esp-idf\soc\libsoc.a
Linking .pio\build\esp32_idf_test\bootloader.elf
c:/users/cmura/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/11.2.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: cannot find -lquarklink-client
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp32_idf_test\bootloader.elf] Error 1

So file is called lib/libquarklink-client.a?

No actually this seems very wrong, with -L/lib you add the absolute path /lib to the library search path, which is the root of your hard drive.

If you want the lib folder of the project to be added to the search path, you just have to juse -Llib instead. Same for the -I flag.

Yes, that is the file name. Its produced from a esp-idf build that appear to add the lib prefix to the file name.

Yes that was it! Thanks so much Max.