ESP-IDF V4.0, "undefined reference to" when working with multiple src files inside main

leofabri
Posts: 9
Joined: Wed Feb 19, 2020 3:36 pm

ESP-IDF V4.0, "undefined reference to" when working with multiple src files inside main

Postby leofabri » Thu Feb 20, 2020 1:45 pm

Hi,
I'm facing a problem when I try to compile an existing project which I'm basically trying to readapt to work with the new version of ESP-IDF V4.0 (the previous one was V3.3).
I noticed that the new development environment uses CMake in order to get the app running so, maybe my "inexperience" is the problem.

When I submit idf.py build flash I get these compilation errors:

app_main.cpp

Code: Select all

FAILED: app.elf 
cmd.exe /C "cd . && C:\Users\leofa\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe --sysroot=c:\development\esp/../xtensa-esp32-elf/xtensa-esp32-elf  -mlongcalls -Wno-frame-address  -nostdlib @CMakeFiles\app.elf.rsp  -o app.elf  && cd ."
c:/users/leofa/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(app_main.cpp.obj):(.literal.app_main+0xc): undefined reference to `MyConfig'
c:/users/leofa/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(app_main.cpp.obj):(.literal.app_main+0x14): undefined reference to `MyCommandApp'
c:/users/leofa/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(app_main.cpp.obj):(.literal.app_main+0x24): undefined reference to `AddTaskToMap(void*)'
c:/users/leofa/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(app_main.cpp.obj):(.literal.app_main+0x28): undefined reference to `AppConfig::mount()'
c:/users/leofa/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(app_main.cpp.obj):(.literal.app_main+0x2c): undefined reference to `AppCommandApp::ConfigureLogging()'
c:/users/leofa/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(app_main.cpp.obj):(.literal.app_main+0x30): undefined reference to `Housekeeping::Housekeeping()'
c:/users/leofa/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(app_main.cpp.obj): in function `app_main':
C:\development\app\build/../main/app_main.cpp:56: undefined reference to `AddTaskToMap(void*)'
c:/users/leofa/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:\development\app\build/../main/app_main.cpp:59: undefined reference to `AppConfig::mount()'
c:/users/leofa/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:\development\app\build/../main/app_main.cpp:62: undefined reference to `AppCommandApp::ConfigureLogging()'
c:/users/leofa/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:\development\app\build/../main/app_main.cpp:68: undefined reference to `Housekeeping::Housekeeping()'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Unfortunately, I can't provide many details about the code in question, but basically I have this structure inside of main:

- CMakeLists.h
- components
- main
-- app_config.cpp
-- app_config.h
-- app_housekeeping.cpp
-- app_housekeeping.h
-- app_commands.cpp
-- app_commands.h
-- app_main.cpp
-- CMakeLists.txt
-- component.mk

CMakeLists.txt outside "main":

Code: Select all

cmake_minimum_required(VERSION 3.5)

set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

set(MDF_VER command bash -c "cd $ENV{MDF_PATH} && git describe --always --tags --dirty")
#CPPFLAGS := -D MDF_VER=\"$(MDF_VER)\"

set(EXTRA_COMPONENT_DIRS $ENV{MDF_PATH}/components $ENV{MDF_PATH}/components/third_party)
#set(EXTRA_COMPONENT_DIRS ${EXTRA_COMPONENT_DIRS} )
message(STATUS "EXTRA_COMPONENT_DIRS: ${EXTRA_COMPONENT_DIRS}")

set(CMAKE_SYSROOT $ENV{IDF_PATH}/../xtensa-esp32-elf/xtensa-esp32-elf)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)

project(app)
CMakeLists.txt inside "main":

Code: Select all

idf_component_register(SRCS "app_main.cpp"
                    INCLUDE_DIRS ".")
Since the problem is at the very beginning of app_main.cpp (right when I call the external functions and classes) I do believe that the problem could be potentially related to CMakeLists.txt that isn't "seeing" those other files inside of main.

Some help would be very appreciated. Thank you in advance

boarchuz
Posts: 606
Joined: Tue Aug 21, 2018 5:28 am

Re: ESP-IDF V4.0, "undefined reference to" when working with multiple src files inside main

Postby boarchuz » Thu Feb 20, 2020 7:38 pm

You need to manually list your source files for main component:

idf_component_register(SRCS "app_main.cpp" "app_config.cpp" "app_housekeeping.cpp" ... etc

leofabri
Posts: 9
Joined: Wed Feb 19, 2020 3:36 pm

Re: ESP-IDF V4.0, "undefined reference to" when working with multiple src files inside main

Postby leofabri » Fri Feb 21, 2020 6:51 am

boarchuz wrote:
Thu Feb 20, 2020 7:38 pm
You need to manually list your source files for main component:

idf_component_register(SRCS "app_main.cpp" "app_config.cpp" "app_housekeeping.cpp" ... etc
Thank you so much. I feel like I should have noticed that by myself but I didn't :lol:

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], iParcelBox and 97 guests