I am running into issues trying to compile the sample esp32_blink project that uses the ESP-IDF with PlatformIO.
Everything links fine it looks like, as I can control-click to all the functions and files, but right when the build is about to finish it errors out with: C:/Users/user/esp/esp-idf/components/freertos/port/port_common.c:125: undefined reference to 'app_main'
I am not the first one to run into this, others have suggested adding extern "C" before the void app_main, but that’s for cpp files, but I am using only C (I tried it anyways and it didn’t work). I am not doing anything special, as my code is straight from the example.
I am really stuck here as I am using the stock example so I shouldn’t have to modify anything; the CMakeLists in the src directory looks like it is including the main.c correctly.
I am using the latest stable version of ESP-IDF, 4.4
Where is the source file located? Did you reference its file name in the src/CMakeLists.txt like the example? Seems like the main.c isn’t compiled at all to me.
From my similar experience, it looks like it could be an error with the linker itself:
// Everything OK, up until the linker
Linking .pio/build/esp32-s3-devkitc-1/firmware.elf
/Users/pjm/.platformio/packages/toolchain-xtensa-esp-elf/bin/…/lib/gcc/xtensa-esp-elf/14.2.0/…/…/…/…/xtensa-esp-elf/bin/ld: .pio/build/esp32-s3-devkitc-1/esp-idf/freertos/libfreertos.a(app_startup.c.o):(.literal.main_task+0x24):
undefined reference to `app_main’
// Then the linker chokes on what I think is just the symbol
// for app_main, given that line 206 of app_startup.c.o is:
ESP_LOGI(MAIN_TAG, “Calling app_main()”);
// The reference to app_main is within a static string,
// so it should not trigger any searches for app_main()
/Users/pjm/.platformio/packages/toolchain-xtensa-esp-elf/bin/…/lib/gcc/xtensa-esp-elf/14.2.0/…/…/…/…/xtensa-esp-elf/bin/ld: .pio/build/esp32-s3-devkitc-1/esp-idf/freertos/libfreertos.a(app_startup.c.o): in function main_task': /Users/pjm/.platformio/packages/framework-espidf/components/freertos/app_startup.c:206:(.text.main_task+0xa4): undefined reference to app_main’
collect2: error: ld returned 1 exit status
*** [.pio/build/esp32-s3-devkitc-1/firmware.elf] Error 1
Is there something I’m missing here? Why would a static text string (not an actual function) on line 206 of app_startup.c throw an error with:
“undefined reference to app_main”
Being a static text string, couldn’t “Calling app_main()” be replaced with “Calling this_text_string_is_not_a_function()” and get back the same error?
Where do you implement your app_main() function, in what file? What do your CMakeLists.txt (in both the root folder of the project and the src/ folder) look like?