Why is WiFi.h not found by compiler

Hi

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.

Belov is the platformIO configuration file.

[env:ESP32-DEV]
platform = espressif32
framework = arduino
board = ESP32dev
board_build.partitions = default_8MB.csv
lib_extra_dirs = 
	${PROJECT_DIR}/../../lib

  
;lib_ldf_mode = chain+
build_flags = 
	-DCORE_DEBUG_LEVEL=5
	-I${PROJECT_DIR}/../../include
	 
monitor_speed = 115200
lib_deps = nkolban/ESP32 BLE Arduino@^1.0.1

PLEASE HELP :grinning:

Try running a verbose build (see PlatformIO IDE for VSCode — PlatformIO latest documentation) which will show you the full commandline passed to the compiler.

You can check which directories are being searched and amend your parameters accordingly.

HTH

Cheers,
Norm.

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.

If the wrappers library was wrongly included, try lib_ignore = wrappers in the platformio.ini.

The same directory contains “i2c_wrapper.h” which is needed by the project.

You are telling me that all files in a referenced directory is compiled, regardless if it is part of the project or not?

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.

What is all this about “dependency graph”??

I expected that PlatformIO scanned through the design. from top to bottom, and only compiled/used included files.

Giving PlatformIO directory paths only was to tell where to search for files.

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 will try to refactor my project so that I include directories with relevant files.

Done.

This is my new configuration file.

[env:ESP32-DEV]
platform = espressif32
framework = arduino
board = ESP32dev
board_build.partitions = default_8MB.csv
lib_extra_dirs = 
	
;lib_ldf_mode = chain+
build_flags = 
	-DCORE_DEBUG_LEVEL=5
	-I${PROJECT_DIR}/../../include
    -I${PROJECT_DIR}/../../lib/mdb

All my source files are located in {PROJECT_DIR}/…/…/lib/mdb

Compiles better than before but… I have a reference to wire.h
The compiler cant find that.
Should it not be a part of espressif32

Try one of those

  • add lib_deps = Wire in the platformio.ini
  • add #include <Wire.h> in one of the project’s main source files
  • activate lib_ldf_mode = chain+.

This works,

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.

Anyhow, thanks… I can go forward again.

1 Like