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.