Include directive for subdirs in library?

I found couple of libs for mbed framework that have some code placed in subdirectories yet they are referenced as if they would be placed in root. I guess online compiler for mbed takes care of adding appropriate directory include directive (in fact you can see this if you export the library on mbed site to “desktop” and specify GCC_ARM platform) but PIO does not specify this directive and compilation fails. Simplest case to reproduce would be to install MODSERIAL (id:218) and try to compile following code:

#include <mbed.h>
#include <MODSERIAL.h>


int main() {
  pc.printf("Hello world\n");

Moreover, when using PIO IDE these header files are missing in project libraries mirror and compilation fails with .pioenvs/disco_f051r8/MODSERIAL_ID218/MACROS.h:26:31: fatal error: MODSERIAL_LPC1768.h: No such file or directory.

What are my options?

You need PlatformIO 3.0 and this feature:

Temporary solution for platformio.ini:

platform = nxplpc
framework = mbed
board = lpc1768
build_flags = -I$BUILD_DIR/MODSERIAL_ID218/Device

Thank you. Could you tag this as FAQ? I guess this is pretty common issue with mbed libs.

Unfortunately there is nothing that could help library builder in such situations. The only place where expected -I and -L directives can be found is export archive from mbed site - it contains ready Makefile to compile the library. So I guess for now we are limited to this workaround, unless library builder will be able to use these Makefiles as reference (which seems unlikely, or is it?).

PlaformIO 3.0 will allow specifying custom flags for the library

1 Like