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.