Collect2.exe: error: ld returned 1 exit status *** [.pio\build\esp32-2432S024C\firmware.elf] Error 1

Hi there,

platformio is really giving me a hard time lately, due to problems and bugs yesterday I did a clean reinstall of platformio. Building was no problem after that.
Today I start Visual Studio again and I get this when compiling:

c:/users/theuser/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32-2432S024C\libFrameworkArduino.a(main.cpp.o):(.literal._Z8loopTaskPv+0x8): undefined reference to `setup()'
c:/users/theuser/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32-2432S024C\libFrameworkArduino.a(main.cpp.o):(.literal._Z8loopTaskPv+0xc): undefined reference to `loop()'
c:/users/theuser/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32-2432S024C\libFrameworkArduino.a(main.cpp.o): in function `loopTask(void*)':       
C:/Users/theuser/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:42: undefined reference to `setup()'
c:/users/theuser/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/Users/theuser/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:48: undefined reference to `loop()'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp32-2432S024C\firmware.elf] Error 1

Even if I didn’t change the code since yesterday I thought there might be some error so I reduced it to:

void setup() { }
void loop() { }

Same problem, also tried clearing the .pio directory.

What is wrong ? :frowning:


What’s the content of your platformio.ini and what the name and location of your source-file?
It should be something like src/main.cpp




; PlatformIO Project Configuration File
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
; Please visit documentation for the other options and examples

#default_envs = esp32-1732S019C
#default_envs = esp32-1732S019N
#default_envs = esp32-2424S012C
#default_envs = esp32-2424S012N
default_envs = esp32-2432S024C
#default_envs = esp32-2432S024N
#default_envs = esp32-2432S024R
#default_envs = esp32-2432S028R
#default_envs = esp32-2432S028Rv2
#default_envs = esp32-2432S032C
#default_envs = esp32-2432S032N
#default_envs = esp32-2432S032R
#default_envs = esp32-3248S035C
#default_envs = esp32-3248S035R
#default_envs = esp32-4827S043C
#default_envs = esp32-4827S043N
#default_envs = esp32-4827S043R
#default_envs = esp32-4848S040C
#default_envs = esp32-8048S043C
#default_envs = esp32-8048S043N
#default_envs = esp32-8048S043R
#default_envs = esp32-8048S050C
#default_envs = esp32-8048S050N
#default_envs = esp32-8048S050R
#default_envs = esp32-8048S070C
#default_envs = esp32-8048S070N

platform = espressif32
framework = arduino

monitor_speed = 115200
#monitor_speed = 9600
monitor_rts = 0
monitor_dtr = 0
monitor_filters = esp32_exception_decoder , send_on_enter

# Partition scheme for OTA
board_build.partitions = min_spiffs.csv

build_flags =
    # LVGL settings

#lib_deps = rzeldent/esp32_smartdisplay
lib_deps =

board = esp32-1732S019C

board = esp32-1732S019N

board = esp32-2424S012C

board = esp32-2424S012N

board = esp32-2432S024C

board = esp32-2432S024N

board = esp32-2432S024R

board = esp32-2432S028R

# Commented out because define creates an error during CI
#board = esp32-2432S028Rv2

board = esp32-2432S032C

board = esp32-2432S032N

board = esp32-2432S032R

board = esp32-3248S035C

board = esp32-3248S035R

board = esp32-4827S043C

board = esp32-4827S043N

board = esp32-4827S043R

board = esp32-8048S043C

board = esp32-8048S043C

board = esp32-8048S043N

board = esp32-8048S043R

board = esp32-8048S050C

board = esp32-8048S050N

board = esp32-8048S050R

board = esp32-8048S070C

board = esp32-8048S070N

Though both didn’t change since yesterday so I suppose it is something caused by the reinstallation of platformio? Some path issues ?

The board names you are using do not exist in the espressif32 platform:

UnknownBoard: Unknown board ID 'esp32-2432S024C'

Are you using a modified platform?

“modified” not really, the board definitions are here:

pretty popular ESP32 backed displays which are sadly not yet in platformio

board definitions in /boards/ parallel to /src/

Ah okay. :slight_smile:

Did you also remove the espressif32 package folder manually?
On a windows system this folder is located at C:\Users\<username>\.platformio\platforms\

yes, removed the whole .patformio path

The error message you describe usually occurs when your main file is named main.c instead of main.cpp - can you please doublecheck this?

Best to also #include <Arduino.h>.

yes it is named main.cpp

@maxgerhardt didn’t really make a difference when it was working, doesn’t make now either, thought that is more arduino specific than ESP32

Can you post the exact project files to the github?

If you do have a src/main.cpp with the empty setup and loop and Arduino include, it can only not work due to some other effect, like, the file is not even compiled due to build src filters, or other very weird things.

This is almost reduced to nothing for the test now, except for the dependencies in the .ini, let me try something different, I’ll just try a new project for another platform and try to compile the “empty” code there.

works for lolin s3 mini though with some “warnings”

.platformio/packages/framework-arduinoespressif32/cores/esp32/esp32-hal-uart.c:149:6: note: declared here
 bool uartSetPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin)

I also have those in the real project though they never were the reason for build errors.

I swapped the ini with my ini now, works so far with the “empty” code. Still no clue what is wrong with the original project but if this works I’ll just paste my stuff over to the newly created.

EDIT: Yes, it worked. So basically created new project with s3mini board instead, copied over ini, src, and board data and it works again. :man_shrugging: