Esp-idf: undefined reference to `app_main' when building project (IDFGH-1318)

Created on 10 Jun 2019  路  11Comments  路  Source: espressif/esp-idf

----------------------------- Delete below -----------------------------

/home/linux/esp32/esp-idf/examples/get-started/ESP32_RC522/build/esp32/libesp32.a(cpu_start.o):(.literal.main_task+0x18): undefined reference to app_main' /home/linux/esp32/esp-idf/examples/get-started/ESP32_RC522/build/esp32/libesp32.a(cpu_start.o): In functionmain_task':
/home/linux/esp32/esp-idf/components/esp32/cpu_start.c:515: undefined reference to `app_main'

Most helpful comment

Did you add:
extern "C" void app_main()

All 11 comments

Do you have void app_main() function in any file in your project?
What is yours folders tree looks like?

If you are using Cmake to build your project, make sure your c source filename is included in CMakeLists.txt under the main folder.

set(COMPONENT_SRCS "hello_world_main.c"
                                              "file1.c"
                                              "file2..c")

According to the docs a CMakeLists.txt file isn't needed under the /main folder. However I'm running into the same issue (having used GNU Make until now).

Hi @f00bard , that part of the docs is outdated, will fix. main should be treated like any other component, with its own CMakeLists.txt.

Hi, @tutuwin
Have you solved this issue?

thanks !!

@tutuwin Closing as there are no updates to the last question by @koobest.

Hi @renzbagaporo ,
I am running in the same kind of problem.
Eclipse_bug_#2

This problem is happening to me because I'm trying to work in c++ with Esp-IDF V4.0 so I renamed the main.c with main.cpp and did the same in the CMakeList.txt.

It work for some time but then the library becomes "unresolved including" and this errors comes with it some time.
I don't totally understand this erros and would like to know of a fix that is good for more then a day.

Thanks

Did you add:
extern "C" void app_main()

I tried it last week and it did'nt work but this time it did.
But new problem,

main.cpp

esp-idf bug #3
It's a C main so can't use any C++ stuff.
It's a more basic problem but could someone help me. I found so little information on this and when I did I'm not sure if it's still good or expired since I'm on ESP-IDF V4.0

Also, I don't have the compiler error but since it still compile my code in C, it does'nt recognize the include in the class.

spi.h

esp-idf bug#4

spi.cpp

esp-idf bug#5

Have you added spi.cpp to the list of source files @Arag0to?

I tried it last week and it did'nt work but this time it did.
But new problem,

main.cpp

esp-idf bug #3
It's a C main so can't use any C++ stuff.
It's a more basic problem but could someone help me. I found so little information on this and when I did I'm not sure if it's still good or expired since I'm on ESP-IDF V4.0

Also, I don't have the compiler error but since it still compile my code in C, it does'nt recognize the include in the class.

spi.h

esp-idf bug#4

spi.cpp

esp-idf bug#5

I have exactly the same issue. I'trying to add an external class (cpp + h). As I'm a beginner in cmake (coming from Visual Studio), can anyone tell me how to include source and header files correctly to project? Thanks a lot.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

feelfreelinux picture feelfreelinux  路  4Comments

ESP32DE picture ESP32DE  路  4Comments

LosDeiblos picture LosDeiblos  路  4Comments

kylefelipe picture kylefelipe  路  3Comments

bfriedkin picture bfriedkin  路  4Comments