undefined reference to `app_main'
-
- Posts: 11
- Joined: Sat Aug 28, 2021 4:02 am
undefined reference to `app_main'
PS E:\esp32\sdk\app\source> idf.py build
Executing action: all (aliases: build)
Running ninja in directory e:\esp32\sdk\app\source\build
Executing "ninja all"...
[1/5] Performing build step for 'bootloader'
ninja: no work to do.
[2/3] Linking CXX executable source.elf
FAILED: source.elf
cmd.exe /C "cd . && E:\esp32\sdk\.espressif\tools\xtensa-esp32-elf\esp-2021r1-8.4.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -mlongcalls -Wno-frame-address @CMakeFiles\source.elf.rsp -o source.elf && cd ."
e:/esp32/sdk/.espressif/tools/xtensa-esp32-elf/esp-2021r1-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/freertos/libfreertos.a(port_common.c.obj):(.literal.main_task+0x14): undefined reference to `app_main'
e:/esp32/sdk/.espressif/tools/xtensa-esp32-elf/esp-2021r1-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/freertos/libfreertos.a(port_common.c.obj): in function `main_task':
E:/esp32/sdk/esp-idf/components/freertos/port/port_common.c:129: undefined reference to `app_main'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1
但是我的app_main()函数是可以找到的,怎么破?????
Executing action: all (aliases: build)
Running ninja in directory e:\esp32\sdk\app\source\build
Executing "ninja all"...
[1/5] Performing build step for 'bootloader'
ninja: no work to do.
[2/3] Linking CXX executable source.elf
FAILED: source.elf
cmd.exe /C "cd . && E:\esp32\sdk\.espressif\tools\xtensa-esp32-elf\esp-2021r1-8.4.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -mlongcalls -Wno-frame-address @CMakeFiles\source.elf.rsp -o source.elf && cd ."
e:/esp32/sdk/.espressif/tools/xtensa-esp32-elf/esp-2021r1-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/freertos/libfreertos.a(port_common.c.obj):(.literal.main_task+0x14): undefined reference to `app_main'
e:/esp32/sdk/.espressif/tools/xtensa-esp32-elf/esp-2021r1-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/freertos/libfreertos.a(port_common.c.obj): in function `main_task':
E:/esp32/sdk/esp-idf/components/freertos/port/port_common.c:129: undefined reference to `app_main'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1
但是我的app_main()函数是可以找到的,怎么破?????
Re: undefined reference to `app_main'
Seems like you want are trying to compile as cpp file.
for that you put the declaration as
extern void app_main()
for that you put the declaration as
extern void app_main()
Re: undefined reference to `app_main'
I have the exact same issue and I am not using CPP file.
c:/espressif/tools/xtensa-esp32-elf/esp-2021r2-patch2-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/freertos/libfreertos.a(port_common.c.obj): in function `main_task':
C:/Espressif/frameworks/esp-idf-v4.4/components/freertos/port/port_common.c:125: undefined reference to `app_main'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1
Any pointers? Thank you.
c:/espressif/tools/xtensa-esp32-elf/esp-2021r2-patch2-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/freertos/libfreertos.a(port_common.c.obj): in function `main_task':
C:/Espressif/frameworks/esp-idf-v4.4/components/freertos/port/port_common.c:125: undefined reference to `app_main'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1
Any pointers? Thank you.
-
- Posts: 9708
- Joined: Thu Nov 26, 2015 4:08 am
Re: undefined reference to `app_main'
Do you have a source file which defines an app_main() function? And if so, is your CMakeLists.txt configured to compile it?
Re: undefined reference to `app_main'
smkaranam wrote: ↑Wed Apr 06, 2022 4:07 pmI have the exact same issue and I am not using CPP file.
c:/espressif/tools/xtensa-esp32-elf/esp-2021r2-patch2-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/freertos/libfreertos.a(port_common.c.obj): in function `main_task':
C:/Espressif/frameworks/esp-idf-v4.4/components/freertos/port/port_common.c:125: undefined reference to `app_main'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1
Any pointers? Thank you.
did you try to compile the hello world example present in the example folder in esp-idf directory?
Re: undefined reference to `app_main'
Check the CMakeLists.txt file of the source code directory ,add it into compile.
# 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 "main.c"
INCLUDE_DIRS "")
# 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 "main.c"
INCLUDE_DIRS "")
Re: undefined reference to `app_main'
Check the \esp-idf\tools\cmake\project.cmake file, it define the component directory of CMakeLists.txt.
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/main")
__project_component_dir("${CMAKE_CURRENT_LIST_DIR}/main")
endif()
So if the app_main function directory is not this main directory, need to modify the project.cmake file.
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/main")
__project_component_dir("${CMAKE_CURRENT_LIST_DIR}/main")
endif()
So if the app_main function directory is not this main directory, need to modify the project.cmake file.
Re: undefined reference to `app_main'
This happens when main.c (or similar) is not listed as a component in project_description.json
To fix this run:
idf.py reconfigure
https://docs.espressif.com/projects/esp ... ystem.html
To fix this run:
idf.py reconfigure
https://docs.espressif.com/projects/esp ... ystem.html
Re: undefined reference to `app_main'
I noticed that on newer esp-idf versions, the reference to 'app_main' only works when the main folder of the project is named "main".
Had it already twice, I think both times with an esp32S3. Lost a lot of time but now I have already changed it in all my projects, even some examples have folder names like "src" where the main.cpp is, the fix for me was to change it to "main".
Had it already twice, I think both times with an esp32S3. Lost a lot of time but now I have already changed it in all my projects, even some examples have folder names like "src" where the main.cpp is, the fix for me was to change it to "main".
-
- Posts: 1
- Joined: Wed Apr 17, 2024 6:59 am
Re: undefined reference to `app_main'
Hi. I am also facing the same issue. I am trying to integrate Matter protocol with an existing IDF project using ESP Matter SDK and ESP32-S3 chip. I am using ESP IDF v5.2.1. @Zyx106 can you please share your CMakeLists file? Thank you.
Who is online
Users browsing this forum: No registered users and 51 guests