ESPRESSIF8266 target code not compiling on new PC but does for a Nano

Since building a new PC I can’t build anything but basic code for a ESPRESSIF8266 device, code that use to work does not compile now and I can’t figure out why…

  1. PIO seems to be automatically “including” any header file in the SRC directory so if the existing code specifically includes the file it I get redefinition errors but if I compile the code to a Nano it’s fine, it doesn’t automatically add it
  2. I can’t use the Serial object/class is in a header file anymore. This compiles, uploads and runs (Serial is being used in main.cpp):


This does not (Serial is being used in debug.h)


But again, if I build the Nano version it all works as expected

This is the PlatformIO.ini


platform = espressif8266

board = d1_mini

upload_protocol = esptool

framework = arduino

lib_ldf_mode = chain+

monitor_speed = 115200


platform = atmelavr

board = nanoatmega328

framework = arduino

lib_ldf_mode = chain+

monitor_speed = 115200

By calling your file debug.h you have created a conflict with Arduino-ESP8266’s debug.h file. Arduino/debug.h at master · esp8266/Arduino · GitHub. Since the Arduino-AVR core for Nano is different, you do not get that error here. To solve the issue, rename debug.h to something unique.

Also, do not implement functions in a .h file, only put the prototype declarations there. Implement them in a .cpp file in your case.

1 Like

Bingo! Thanks, that’s worked!

I’m a VB developer so still getting use to how to do things properly!!