Migrating project from Arduino IDE, won't compile

Apologies for starting the 1,000th thread on this issue… I’m new to PlatformIO and probably (hopefully) just doing something stupid!

I’m migrating a project that compiled and worked fine in the Arduino IDE. I loaded it into PlatformIO and of course got a ton of errors. I created prototypes for all my functions and put them into .h files (that were then included in the .cpp files), chased down a ton of other issues and now have no errors showing in the IDE. But the project still won’t compile - I’m getting a multitude of “multiple definition of…” errors, and at the end of compiling (linking, actually), the dreaded “Error 1”.

A little background, I’m on Windows 11, and the target is an M5Dial which has an ESP32-S3 processor.

Here’s an example of one of the errors:

c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `OnESPNowDataSent(unsigned char const*, esp_now_send_status_t)':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:75: multiple definition of `OnESPNowDataSent(unsigned char const*, esp_now_send_status_t)'; .pio/build/m5stack-stamps3/src/Communication.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:75: first defined here

The HVAC20WallController.h file:

#include <arduino.h>
#include "HVACEnums.h"
#include "M5Dial.h"
#include <esp_task_wdt.h>
#include <esp_now.h>
#include <esp_wifi.h>
#include "driver/temp_sensor.h"  //For on-chip temp sensor
#include <WiFi.h>
#include <Preferences.h>
#include <uptime.h>
#include <uptime_formatter.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/timers.h"
#include "freertos/event_groups.h"
#include <Adafruit_VEML7700.h>
#include <Adafruit_SHT31.h>
#include "uTimerLib.h"
#include <SPI.h>

void initESPTempSensor();
void getSettings();
void saveSettings();
void bgBacklightTask(void* parameter);
void getSensorReadings();
void getAndSendSensorReadings();
void toggleZoneState();
void doTimerTick();
void doTimerTick(bool bResetTransmit);
void OnESPNowDataSent(const uint8_t *mac_addr, esp_now_send_status_t status);

And at the top of the HVAC20WallController.cpp file:

#include <HVAC20WallController.h>

The function it’s complaining about (“OnESPNowDataSent”, right?) is absolutely only defined once, in Communication.cpp.

There are also a few different errors right at the end of the output:

c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o:(.literal._Z5setupv+0x68): undefined reference to `OnESPNowDataSent(unsigned char const*, esp_now_send_status_t)'
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/Communication.cpp.o:(.literal._Z11attemptPairv+0x28): undefined reference to `esp_wifi_set_channel(unsigned char, wifi_second_chan_t)'
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/Communication.cpp.o: in function `attemptPair()':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:248: undefined reference to `esp_wifi_set_channel(unsigned char, wifi_second_chan_t)'

So maybe it’s one of those that’s the problem?

Relative to the very last one, I have included esp_now.h and WiFi.h.

I also have:

esp_err_t esp_wifi_set_channel(unsigned char primary, wifi_second_chan_t second);

…in my Communication.h file (header for Communication.cpp). I find it odd that I have to put that there but if I don’t the compiler complains.

The exact error message is:

collect2.exe: error: ld returned 1 exit status
*** [.pio\build\m5stack-stamps3\firmware.elf] Error 1

Can anyone help with this? If necessary I can paste or upload more data or the files - I just don’t want to make this post crazy long.

Your HVAC20WallController.h header file is missing an include guard!
Check include guard - Wikipedia

Thanks! But, it doesn’t seem to have made any difference?

Here’s what HVAC20WallController.h looks like now:

#ifndef WC_INCL_DEF
#define WC_INCL_DEF

#include <arduino.h>
#include "HVACEnums.h"
#include "M5Dial.h"
#include <esp_task_wdt.h>
#include <esp_now.h>
#include <esp_wifi.h>
#include "driver/temp_sensor.h"  //For on-chip temp sensor
#include <WiFi.h>
#include <Preferences.h>
#include <uptime.h>
#include <uptime_formatter.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/timers.h"
#include "freertos/event_groups.h"
#include <Adafruit_VEML7700.h>
#include <Adafruit_SHT31.h>
#include "uTimerLib.h"
#include <SPI.h>

void initESPTempSensor();
void getSettings();
void saveSettings();
void bgBacklightTask(void* parameter);
void getSensorReadings();
void getAndSendSensorReadings();
void toggleZoneState();
void doTimerTick();
void doTimerTick(bool bResetTransmit);
void OnESPNowDataSent(const uint8_t *mac_addr, esp_now_send_status_t status);

#endif

And if it helps any, here’s the entire compiler output:

Processing m5stack-stamps3 (platform: espressif32; board: m5stack-stamps3; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/m5stack-stamps3.html
PLATFORM: Espressif 32 (6.9.0) > M5Stack StampS3
HARDWARE: ESP32S3 240MHz, 320KB RAM, 8MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-builtin, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 3.20017.241212+sha.dcc1105b
 - tool-esptoolpy @ 4.7.4
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
 - toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 45 compatible libraries
Scanning dependencies...
Dependency Graph
|-- M5Dial @ 1.0.2
|-- M5Unified @ 0.2.2
|-- Adafruit SHT31 Library @ 2.2.2
|-- Adafruit VEML7700 Library @ 2.1.6
|-- Adafruit BusIO @ 1.17.0
|-- Uptime Library @ 1.0.0
|-- LittleFS @ 2.0.0
|-- OpenFontRender @ 1.2.0
|-- TFT_eSPI @ 2.5.43
|-- WiFi @ 2.0.0
|-- uTimerLib @ 1.7.2
|-- Preferences @ 2.0.0
|-- SPI @ 2.0.0
Building in release mode
Compiling .pio\build\m5stack-stamps3\src\HVAC20WallController.cpp.o
src/HVAC20WallController.cpp:19:9: warning: #pragma once in main file
 #pragma once
         ^~~~
Linking .pio\build\m5stack-stamps3\firmware.elf
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `doDataTransmit()':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:37: multiple definition of `doDataTransmit()'; .pio/build/m5stack-stamps3/src/Communication.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:37: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `OnDataSent(unsigned char const*, esp_now_send_status_t)':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:73: multiple definition of `OnDataSent(unsigned char const*, esp_now_send_status_t)'; .pio/build/m5stack-stamps3/src/Communication.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:73: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `bootScreenLog(String)':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:52: multiple definition of `bootScreenLog(String)'; .pio/build/m5stack-stamps3/src/DisplayFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:52: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `attemptPair()':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:240: multiple definition of `attemptPair()'; .pio/build/m5stack-stamps3/src/Communication.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:240: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `showCurZoneState()':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:154: multiple definition of `showCurZoneState()'; .pio/build/m5stack-stamps3/src/DisplayFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:154: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `eTaskStateDesc(eTaskState)':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:306: multiple definition of `eTaskStateDesc(eTaskState)'; .pio/build/m5stack-stamps3/src/DisplayFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:306: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:20: multiple definition of `bDisplayBusy'; .pio/build/m5stack-stamps3/src/DisplayFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:20: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `showCurTemp()':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:92: multiple definition of `showCurTemp()'; .pio/build/m5stack-stamps3/src/DisplayFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:92: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `showCurHeatPumpStatus()':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:163: multiple definition of `showCurHeatPumpStatus()'; .pio/build/m5stack-stamps3/src/DisplayFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:163: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `setPairingMode()':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:221: multiple definition of `setPairingMode()'; .pio/build/m5stack-stamps3/src/Communication.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:221: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `setPairedMode()':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:230: multiple definition of `setPairedMode()'; .pio/build/m5stack-stamps3/src/Communication.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:230: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `showCurMode()':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:263: multiple definition of `showCurMode()'; .pio/build/m5stack-stamps3/src/DisplayFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:263: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `showSetTemp()':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:64: multiple definition of `showSetTemp()'; .pio/build/m5stack-stamps3/src/DisplayFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:64: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:35: multiple definition of `peerInfoCentralController'; .pio/build/m5stack-stamps3/src/Communication.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:35: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `OnDataRecv(unsigned char const*, unsigned char const*, int)':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:87: multiple definition of `OnDataRecv(unsigned char const*, unsigned char const*, int)'; .pio/build/m5stack-stamps3/src/Communication.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:87: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `drawScreen()':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:30: multiple definition of `drawScreen()'; .pio/build/m5stack-stamps3/src/DisplayFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:30: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `switchToScreen(DeviceScreen)':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:22: multiple definition of `switchToScreen(DeviceScreen)'; .pio/build/m5stack-stamps3/src/DisplayFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/DisplayFuncs.cpp:22: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/HMIFuncs.cpp:13: multiple definition of `prev_touch_state'; .pio/build/m5stack-stamps3/src/HMIFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/HMIFuncs.cpp:13: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/HMIFuncs.cpp:14: multiple definition of `prev_touch_x'; .pio/build/m5stack-stamps3/src/HMIFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/HMIFuncs.cpp:14: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/HMIFuncs.cpp:15: multiple definition of `prev_touch_y'; .pio/build/m5stack-stamps3/src/HMIFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/HMIFuncs.cpp:15: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `doHMITouchscreen()':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/HMIFuncs.cpp:43: multiple definition of `doHMITouchscreen()'; .pio/build/m5stack-stamps3/src/HMIFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/HMIFuncs.cpp:43: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/HMIFuncs.cpp:12: multiple definition of `buttonHeld'; .pio/build/m5stack-stamps3/src/HMIFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/HMIFuncs.cpp:12: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `doHMIPushbutton()':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/HMIFuncs.cpp:17: multiple definition of `doHMIPushbutton()'; .pio/build/m5stack-stamps3/src/HMIFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/HMIFuncs.cpp:17: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o: in function `doHMIEncoder()':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/HMIFuncs.cpp:88: multiple definition of `doHMIEncoder()'; .pio/build/m5stack-stamps3/src/HMIFuncs.cpp.o:C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/HMIFuncs.cpp:88: first defined here
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/HVAC20WallController.cpp.o:(.literal._Z5setupv+0x68): undefined reference to `OnESPNowDataSent(unsigned char const*, esp_now_send_status_t)'
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/Communication.cpp.o:(.literal._Z11attemptPairv+0x28): undefined reference to `esp_wifi_set_channel(unsigned char, wifi_second_chan_t)'
c:/users/eric.home/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/m5stack-stamps3/src/Communication.cpp.o: in function `attemptPair()':
C:\Users\eric.HOME\Documents\PlatformIO\Projects\HVAC20 Wall Controller/src/Communication.cpp:248: undefined reference to `esp_wifi_set_channel(unsigned char, wifi_second_chan_t)'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\m5stack-stamps3\firmware.elf] Error 1

It’s difficult to analyze isolated code snippets. There seem to be other files involved that also have problems.

Can you share the complete project (e.g. on github)?

Actually I figured it out! Which is good because I don’t know how to upload to Github. ;^)

It was a really stupid problem. I’ve been programming for a long time, but not in C/C++, and most of my experience with those languages was in the Arduino IDE which of course does a lot of hand-holding.

One thing I was really unfamiliar with was function prototypes… I sort of knew that they were needed, but didn’t give enough thought to why they’re needed and where to put them.

So… when I first tried to compile my program, I got a ton of errors about functions being undefined. And me being the clever one I am, I “fixed” it by #include’ing my other source files in the main file.

In hindsight it’s of course obvious what went wrong… the functions in those files were in fact defined twice… once in the file itself, and again when the same file was included in the main file.

Removing the #includes and rearranging things fixed the problem. I also made a single .h file with all the function prototypes and included it in the other files for convenience, which seems to work well.

Now I’ve got a problem with the target getting stuck in a boot loop, but if I can’t figure it out I’ll open another thread for that issue.

3 Likes