PlatformIO and Clion undefined reference

Hello

I’m new with platform io and i try to use on Clion IDE.
When I try to compile my projet, that not working and i get this error message

====================[ Build | Debug | az-delivery-devkit-v4 ]===================
C:\Users\paulp\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\201.6668.126\bin\cmake\win\bin\cmake.exe --build C:\Users\paulp\CLionProjects\az\cmake-build-az-delivery-devkit-v4 --target Debug -- -j 8
Processing az-delivery-devkit-v4 (platform: espressif32; board: az-delivery-devkit-v4; framework: arduino)
-------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/az-delivery-devkit-v4.html
PLATFORM: Espressif 32 1.12.0 > AZ-Delivery ESP-32 Dev Kit C V4
HARDWARE: ESP32 240MHz, 520KB RAM, 16MB Flash
DEBUG: Current (esp-prog) External (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.10004.200129 (1.0.4) 
 - tool-esptoolpy 1.20600.0 (2.6.0) 
 - toolchain-xtensa32 2.50200.80 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 29 compatible libraries
Scanning dependencies...
No dependencies
Building in debug mode
Compiling .pio\build\az-delivery-devkit-v4\src\main.c.o
Linking .pio\build\az-delivery-devkit-v4\firmware.elf
.pio\build\az-delivery-devkit-v4\libFrameworkArduino.a(main.cpp.o):(.literal._Z8loopTaskPv+0x4): undefined reference to `setup()'
.pio\build\az-delivery-devkit-v4\libFrameworkArduino.a(main.cpp.o):(.literal._Z8loopTaskPv+0x8): undefined reference to `loop()'
.pio\build\az-delivery-devkit-v4\libFrameworkArduino.a(main.cpp.o): In function `loopTask(void*)':
C:\Users\paulp\.platformio\packages\framework-arduinoespressif32\cores\esp32/main.cpp:14: undefined reference to `setup()'
C:\Users\paulp\.platformio\packages\framework-arduinoespressif32\cores\esp32/main.cpp:17: undefined reference to `loop()'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\az-delivery-devkit-v4\firmware.elf] Error 1
========================= [FAILED] Took 6.78 seconds =========================
mingw32-make.exe[3]: *** [CMakeFiles/Debug] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Debug.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Debug.dir/rule] Error 2
CMakeFiles\Debug.dir\build.make:56: recipe for target 'CMakeFiles/Debug' failed
CMakeFiles\Makefile2:105: recipe for target 'CMakeFiles/Debug.dir/all' failed
CMakeFiles\Makefile2:112: recipe for target 'CMakeFiles/Debug.dir/rule' failed
Makefile:130: recipe for target 'Debug' failed
mingw32-make.exe: *** [Debug] Error 2

i use MinGW and Clion 2020.1

remarq. if I use Clion i use VSCode. PlatformIO work fine

Thank you

Arduino is a C++ framework yet you have called the main faile main.c and not main.cpp. The linking fails due to it not finding the C++ function setup() and loop() (remember, C++ has name mangling).

1 Like

OOOH thank you so mush !!!
I had it under my nose without seeing it

it’s normal platformio genrate me a main.c not a main.cpp ?

PlatformIO should generated a project without any sources (empty src/) folder.

What steps did you take to create the project?

i follow this instruction https://docs.platformio.org/en/latest/integration/ide/clion.html

that create me src folder with empty main.c source file

That’s correct, so it does that. But in step 2 it also tells you to rename the file. (CLion — PlatformIO latest documentation). The tool seems to always generate main.c.

hum :flushed: i read too fast.
thank you again !