Undefined reference to `app_main'

When trying to create a blank project, I always get undefined reference to 'app_main'. When I select Arduino as framework it works but not with idf. Maybe it is because of the new idf 5.X version? If yes, how to change that during project setup?

Can you pload your project files? (Without .pio folder)

Using VS Code Version: 1.80.1 (Universal)
Platformio: Core 6.1.9 Home 3.4.4

Can you replace the contents of the src/CMakeLists.txt with

idf_component_register(SRCS "main.c"
                    INCLUDE_DIRS ".")

?

1 Like

Sadly gives me the same error:

/esp/esp-idf/components/freertos/port/port_common.c:135: undefined reference to `app_main'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Hi I’m here with the same error. And I’ve googling it for days without any solution.

esp/esp-idf/components/freertos/app_startup.c:206: undefined reference to `app_main’

how can it be that hard to solve this problem ??

I have the main.c file

void app_main(void)
{
printf(ā€œHello world!\nā€);

sem_vsync_end = xSemaphoreCreateBinary();
assert(sem_vsync_end);
sem_frame_buffer_ready = xSemaphoreCreateBinary();
assert(sem_frame_buffer_ready);

}

I’ve rename it to app_main.c and app_main.cpp. Everytime I do it. I’ve update the CMake file. PIO and VScode and ESP-IDF all of them are up to date. What do we missing?

This file was automatically generated for projects

without default ā€˜CMakeLists.txt’ file.

FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/.)

idf_component_register(SRCS ${app_sources})

idf_component_register(SRCS ā€œapp_main.cppā€
INCLUDE_DIRS ā€œ.ā€)

IT WORK FOR ME…!!! DAMM i been having a long week trying to figure that out…

Thanks so Much

What worked for you? I don’t see where\how the issue was resolved.

The error usually comes from either the source file containing the app_main() function not being compiled due an error in your CMake files, or the function being defined in a .cpp but lacking the extern "C" (the function needs to have C linkage). Post your whole project files if you’re still having problems.

1 Like

If anyone else is still having this issue and ends up here through google I figured out why I was having this issue.
If you have both platformIO and the espIDF extensions installed you will have two different build buttons one is through the IDF the other through platformIO.
espIDF can’t build a platformIO project without a bunch of make file edits hence this error.

So if you have this error make sure you’re using the PIO build button.

Thank you very much for coming back and posting the solution. I was facing the same issue and your post saved me hours. Thanks!