Platform windows_x86 problem with libs / Compatibility Mode


I am trying to target some parts of my embedded code to my PC, using the windows_x86 platform. I put some custom libraries under lib, and tried to include the header files in my source. Unfortunately, this fails with errors such as src\main.cpp:1:18: fatal error: test.h: No such file or directory.

This problem does not occur if I switch to an embedded target such as stm32. It can be also be worked around by moving the libraries to the src folder, but I guess this is bad practice.


Could you provide simple project to reproduce this issue?

Here is a trivial example

#include <test.h>
#include <stdio.h>

int main()

where test.h is an empty file, located under libs.

The example compiles fine if test.h is located under src. However, just now I noticed that the compiled program.exe does not run successfully. It gives the following error, which suggests that some libraries are missing, or not in the path

Could you provide full build output log? pio run -v. Thanks!

Hello Ivan,

Here is the result of pio run -v.

[11/23/16 21:08:59] Processing commandline (platform: windows_x86, build_flags: -DCOMMANDLINE)
-------------------------------------------------------------------------------------------------------------------- CFollected 0 compatible libraries
Looking for dependencies...
ramework incompatible library C:\Users\dap124\.platformio\lib\RadioHead_ID124
MProject does not have dependencies
ore details about "Library Compatibility Mode":
g++ -o .pioenvs\commandline\src\main.o -c -DPLATFORMIO=030100 -DCOMMANDLINE -Isrc src\main.cpp
src\main.cpp:1:18: fatal error: test.h: No such file or directory
compilation terminated.
*** [.pioenvs\commandline\src\main.o] Error 1
============================================ [ERROR] Took 1.27 seconds ============================================

Could you provide full log/project without errors? How I can reproduce it?

Apart from main.cpp, the only other files are test.h (empty), and platformio.ini, with the following contents:

# Command line windows to generate config bytes
platform = windows_x86
build_flags = -DCOMMANDLINE

Looking at the verbose output, and comparing with other platforms that work fine, it seems that -Ilib switch is missing for some reason.

Thanks! I found a similar issue

Will fix it later.

PlatformIO works in lib_compat_mode = 1 by default. See Library Dependency Finder (LDF) — PlatformIO latest documentation

If you want to force PIO build library that is not compatible with your build environment, set lib_compat_mode = 0 for this build environment.

This problem seems to have been fixed in platformio 3.2.0b6. It does not require any changes to lib_compat_mode, as this is my own library which should be compatible with any platform. The only point is that files cannot be directly under lib, they must be in e.g. lib/libfoo.

You are right. Please read

@ivankravets, although compilation works fine, I’m now having trouble running the generated code.

By default, mingw32 executables use shared libraries, and the required dll libraries are not put into the path by default when platformio installs its mingw32 compiler.

Of course, as a workaround I can manually add the relevant folder to my path. However, I think that a more sensible default would be to generate statically linked executables.

According to what I found online, the correct way to do this is to add the flags -static -static-libgcc -static-libstdc++ when linking. I tried adding these to build_flags, but it does not help. Running pio run -v confirms that these options are added to the compilation command, instead of the linking command where they are needed.

Please try with -Wl, prefix if you want to pass option to GCC linker.

@ivankravets, that is part way to the solution. Having the line

build_flags = -Wl,-static,-static-libgcc,-static-libstdc++

Gives the error

ld.exe: unrecognized -a option `tic-libgcc'

This suggests that the option -static-libgcc is causing problems. I believe it is only supported on some more recent gcc versions, I’m not sure if the bundled mingw32 gcc has support.

Having only -Wl,static compiles fine, and I see that this option gets passed to the linker. However, it does not solve the dll dependency.

Try this

build_flags = -Wl,-static -Wl,-static-libgcc -Wl,-static-libstdc++

Other solution

extra_script =



This gives the same error as before.

Yes, this workaround solves the issue, and for my current problem this is good enough. It would be great if this was the default behaviour for all desktop targets. Let me know if you decide to fix this, and I’ll be happy to test.

Done! Please remove extra script and run pio update.

Thanks @ivankravets. Confirming that the fix works fine.

1 Like