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.
#include <test.h>
#include <stdio.h>
int main()
{
printf("Testing\n");
}
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
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.
@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.
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.
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.