I am developing a ESP32 application that is getting bigger and bigger. To be able to perform integration tests I have a lot of platformIO projects set up, refereing back to the original application.
For a specific “integration test” can this be seen by the reference in platform.ini file
${PROJECT_DIR}/../../lib
No, suddenly, ( I write suddenly because this have been working ) I have run into a strange problem. The compiler can not find a file that is part of the espressif platform.
Compiling .pio\build\ESP32-DEV\FrameworkArduino\MD5Builder.cpp.o
Compiling .pio\build\ESP32-DEV\FrameworkArduino\Print.cpp.o
In file included from C:\hostedProjects\psm\mdcb\lib\wrappers\wifi_wrapper.cpp:22:0:
C:\hostedProjects\psm\mdcb\lib\wrappers\wifi_wrapper.h:9:18: fatal error: WiFi.h: No such file or directory
The file exists ( i can use file explorer and verify that ) but the compiler cant find it. My guess is that the search/include path for the compiler is somehow wrong but I cant find a way to correct it.
I’ve spent a day with this problem and need some fresh ideas.
Well, running i verbose mode don’t help me much, I have alread observed that the compiler compiles files not part of this project.
I have this reference:
${PROJECT_DIR}/../../lib
There is a file “${PROJECT_DIR}/…/…/lib/wrapper/i2c_wrapper.h” that are needed.
In the same directory we have “ble_wrapper.h” and “wifi.wrapper.h”, files that not are part of this project. When the compiler tries to compile files those, errors occurs vecause the files contains referenses to espressif32 packages.
Root cause is that this files are compiled from the beginning.
Below I added a screendump of my project. Dolders “lib” and “include” are added using vscode workspace. In the file system they are one level up.
All .cpp files in a library are compiled unless filtered out through by a srcFilter or through extraScript. The build system by default has no idea that you want to cherry-pick sources from a library folder.
Inclusion of a library by default is a whole-or-nothing thing. If the library dependency finder sees you include a header file that is contained in one of the libraries in its search paths, it will add the whole library to the build process and to the dependency graph. Every source of it, unless specified otherwise by the library.json options linked above.
Easy fix in the code that doesn’t depend on PlatformIO: Use globally available compile-time macros like ARDUINO_ARCH_ESP32 or ARDUINO_ARCH_ESP8266 to wrap the header and implementation.
#ifndef _WIFI_WRAPPER_H
#define _WIFI_WRAPPER_H
/* inner content only filled with stuff if we're on esp32 or esp8266 platforms.. */
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
#include <WiFi.h>
/* other stuff */
#endif
#endif
same for the .cpp file. This requires lib_ldf_mode = chain+ to evaluate the macros correctly for the LDF.
Or, use a simple extra script per link above to include/exclude wifi_wrapper.cpp/h from the build process if the platform is not espressif32.
But in any case, that doesn’t seem to be the actual problem here since you don’t have the problem of trying to find WiFi.h on a non-WiFi platform. You’re compiling for an ESP32 where it should be found.
If you’ve already tried lib_ldf_mode = chain+, please upload a minimal project that reproduces the problem.
I know that PlatformIO have started from a wish to make life easier for unexperienced users, but lately I have started to think that PlatformIO itself, have started to be so complicated that you spend more time struggle with PlatformIO than your actual project.