How to fix PlatformIO multiple definition of `WiFi' error
Problem:
When compiling your PlatformIO firmware, you see an error message like
Linking .pio/build/d1_mini_lite/firmware.elf
/home/uli/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld: .pio/build/d1_mini_lite/libbc0/libWiFi.a(WiFi.cpp.o):(.bss.WiFi+0x0): multiple definition of `WiFi'; .pio/build/d1_mini_lite/libd39/libESP8266WiFi.a(ESP8266WiFi.cpp.o):(.bss.WiFi+0x0): first defined here
collect2: error: ld returned 1 exit status
*** [.pio/build/d1_mini_lite/firmware.elf] Error 1
Solution
Move WiFi
in the lib_deps
section in platformio.ini
to the top of the list. Before the fix:
lib_deps =
ESP Async [email protected]
[email protected]
WiFi
After the fix:
lib_deps =
WiFi
ESP Async [email protected]
[email protected]
Now you need to completely remove the .pio
folder from your project directory:
rm -rf .pio
After that, recompile your firmware.
Complete platformio.ini
example after fixing the issue:
[env:d1_mini_lite]
platform = espressif8266
board = d1_mini_lite
framework = arduino
monitor_speed = 115200
lib_deps =
WiFi
ESP Async [email protected]
[email protected]