PlatformIO Community

ESP32 & freertos & port_common.o & undefined reference to app_main

Hello,

When i link my program, i have this error :
(i have a main.cpp with an entry named void app_main())

c:/users/josem/.platformio/packages/toolchain-xtensa32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32doit-devkit-v1\esp-idf\freertos\libfreertos.a(port_common.o):(.literal.main_task+0x14): undefined reference to app_main' c:/users/josem/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32doit-devkit-v1\esp-idf\freertos\libfreertos.a(port_common.o): in function main_task’:
C:\Users\josem.platformio\packages\framework-espidf\components\freertos\port/port_common.c:129: undefined reference to `app_main’
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp32doit-devkit-v1\firmware.elf] Error 1

Could you please help me

JoseMiguel

You wrote it like

extern "C" void app_main() {
  //..
}

, to correctly expose the symbol app_main without C++ name mangling, right?

1 Like

Hi maxgerhardt,

Thank you very much, merci

JoseMiguel

This is the correct solution, but for folks confused by the past-tense phrase:
“You wrote it…”
change that to:
“You need to write it…”
That might clarify the answer… Thanks maxgerhardt for the answer.

I’ve got more or less the same problem … but I don’t understand the solution …


My errors look like:

[build] [ 99%] Linking CXX executable hello_opencv.elf

[build] /home/mongoq/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld: esp-idf/freertos/libfreertos.a(port_common.c.obj):(.literal.main_task+0x1c): undefined reference to `app_main’

[build] /home/mongoq/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld: esp-idf/freertos/libfreertos.a(port_common.c.obj): in function `main_task’:

[build] /home/mongoq/.platformio/packages/framework-espidf/components/freertos/port/port_common.c:122: undefined reference to `app_main’

[build] collect2: error: ld returned 1 exit status

[build] make[2]: *** [hello_opencv.elf] Error 1

[build] make[1]: *** [CMakeFiles/hello_opencv.elf.dir/all] Error 2

[build] make: *** [all] Error 2

[build] CMakeFiles/hello_opencv.elf.dir/build.make:423: recipe for target ‘hello_opencv.elf’ failed

[build] CMakeFiles/Makefile2:554: recipe for target ‘CMakeFiles/hello_opencv.elf.dir/all’ failed

[build] Makefile:129: recipe for target ‘all’ failed

[build] Build finished with exit code 2


The hello_opencv.cpp function looks like:

#inlcude

extern “C” {

void app_main(void);

}

void app_main(void)

{ … }


Regards,
mongoq