Page 2 of 2

Re: undefined reference to `app_main'

Posted: Tue May 07, 2024 5:06 pm
by oarcher
I was also facing this issue, when trying to compile cpp files.

check that you have in your top CMakeLists.txt:

Code: Select all

cmake_minimum_required(VERSION 3.6)
set(CMAKE_CXX_STANDARD 17)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(myproj)
And in main/myproj.cpp:

Code: Select all

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

Re: undefined reference to `app_main'

Posted: Tue Oct 01, 2024 7:36 am
by striderheng
If you check here, https://docs.espressif.com/projects/esp ... ystem.html
under renaming main component, it gives you instructions if you are not using main.c or main directory.
In my case I am using src directory with main.cpp as the file with my 'main code'

Adding src to the root project Cmakelists file with the below helped.

set(EXTRA_COMPONENT_DIRS src ../commoncomponents )

Also running idf.py reconfigure task (you can find this in VIEW..COMMAND PALETTE) usually helps when you have changes Cmale needs to know about.

if you are coding in CPP, you need to use

extern "C" void app_main(void)

instead of the app_main() for if you are using C