How to include subcomponents inside ESP-IDF

veso266
Posts: 1
Joined: Fri Mar 15, 2024 9:05 pm

How to include subcomponents inside ESP-IDF

Postby veso266 » Wed Apr 17, 2024 8:13 pm

Hello there, its my first time developing with ESP32 and using its ESP-IDF Build System

I created a project with

idf.py create-project BlueFW
idf.py set-target esp32
idf.py menuconfig
to enable Bluetooth and C++ exeptions

then I started adding files inside
Image

my CMakeLists.txt inside main looks like

Code: Select all

idf_component_register(SRCS "main.cpp" "BLENotifyApp.cpp"
                    INCLUDE_DIRS ".")
But linker does not want to link it complains

Code: Select all

Executing action: all (aliases: build)
Running ninja in directory L:\projects\me-projekto\projektoHW\build
Executing "ninja all"...
[1/6] Performing build step for 'bootloader'

[1/1] cmd.exe /C "cd /D L:\projects\me-projekto\projektoHW\build\bootloader\esp-idf\esptool_py && C:\esp\python_env\idf5.0_py3.8_env\Scripts\python.exe C:/esp/frameworks/esp-idf-v5.0/components/partition_table/check_sizes.py --offset 0x8000 bootloader 0x1000 L:/projects/me-projekto/projektoHW/build/bootloader/bootloader.bin"

Bootloader binary size 0x6710 bytes. 0x8f0 bytes (8%) free.

[2/4] Linking CXX executable BlueTempHW.elf

FAILED: BlueTempHW.elf 

cmd.exe /C "cd . && C:\esp\tools\xtensa-esp32-elf\esp-2022r1-11.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -mlongcalls -Wno-frame-address  @CMakeFiles\BlueTempHW.elf.rsp -o BlueTempHW.elf  && cd ."

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZN17MyServerCallbacksD5Ev[_ZN17MyServerCallbacksD5Ev]+0x4): undefined reference to `vtable for BLEServerCallbacks'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZN12MyNotifyTask3runEPv[_ZN12MyNotifyTask3runEPv]+0x4): undefined reference to `Task::delay(int)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZN12MyNotifyTask3runEPv[_ZN12MyNotifyTask3runEPv]+0x8): undefined reference to `BLECharacteristic::setValue(unsigned char*, unsigned int)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZN12MyNotifyTask3runEPv[_ZN12MyNotifyTask3runEPv]+0xc): undefined reference to `BLECharacteristic::notify(bool)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZN12MyNotifyTaskD5Ev[_ZN12MyNotifyTaskD5Ev]+0x4): undefined reference to `Task::~Task()'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZN17MyServerCallbacks12onDisconnectEP9BLEServer[_ZN17MyServerCallbacks12onDisconnectEP9BLEServer]+0x4): undefined reference to `Task::stop()'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZN17MyServerCallbacks9onConnectEP9BLEServer[_ZN17MyServerCallbacks9onConnectEP9BLEServer]+0x0): undefined reference to `Task::start(void*)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZL3runv+0x24): undefined reference to `Task::Task(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned short, unsigned char)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZL3runv+0x28): undefined reference to `Task::setStackSize(unsigned short)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZL3runv+0x2c): undefined reference to `BLEDevice::init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZL3runv+0x30): undefined reference to `BLEDevice::createServer()'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZL3runv+0x34): undefined reference to `BLEServer::setCallbacks(BLEServerCallbacks*)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZL3runv+0x38): undefined reference to `BLEUUID::BLEUUID(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZL3runv+0x3c): undefined reference to `BLEServer::createService(BLEUUID, unsigned long, unsigned char)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZL3runv+0x40): undefined reference to `BLEService::createCharacteristic(BLEUUID, unsigned long)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZL3runv+0x44): undefined reference to `BLE2902::BLE2902()'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZL3runv+0x48): undefined reference to `BLECharacteristic::addDescriptor(BLEDescriptor*)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZL3runv+0x4c): undefined reference to `BLEService::start()'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZL3runv+0x50): undefined reference to `BLEServer::getAdvertising()'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.literal._ZL3runv+0x54): undefined reference to `BLEAdvertising::start()'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj): in function `MyNotifyTask::run(void*)':

L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:31: undefined reference to `Task::delay(int)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:33: undefined reference to `BLECharacteristic::setValue(unsigned char*, unsigned int)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:34: undefined reference to `BLECharacteristic::notify(bool)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj): in function `MyNotifyTask::~MyNotifyTask()':

L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:27: undefined reference to `Task::~Task()'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj): in function `MyNotifyTask::~MyNotifyTask()':

L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:27: undefined reference to `Task::~Task()'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj): in function `MyServerCallbacks::onDisconnect(BLEServer*)':

L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:49: undefined reference to `Task::stop()'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj): in function `MyServerCallbacks::onConnect(BLEServer*)':

L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:45: undefined reference to `Task::start(void*)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj): in function `MyNotifyTask::MyNotifyTask()':

L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:27: undefined reference to `Task::Task(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned short, unsigned char)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj): in function `run()':

L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:55: undefined reference to `Task::setStackSize(unsigned short)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:58: undefined reference to `BLEDevice::init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:61: undefined reference to `BLEDevice::createServer()'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:62: undefined reference to `BLEServer::setCallbacks(BLEServerCallbacks*)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:65: undefined reference to `BLEUUID::BLEUUID(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:65: undefined reference to `BLEServer::createService(BLEUUID, unsigned long, unsigned char)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:68: undefined reference to `BLEUUID::BLEUUID(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:68: undefined reference to `BLEService::createCharacteristic(BLEUUID, unsigned long)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:78: undefined reference to `BLE2902::BLE2902()'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:78: undefined reference to `BLECharacteristic::addDescriptor(BLEDescriptor*)'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:81: undefined reference to `BLEService::start()'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:84: undefined reference to `BLEServer::getAdvertising()'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: L:/projects/me-projekto/projektoHW/main/BLENotifyApp.cpp:84: undefined reference to `BLEAdvertising::start()'

c:/esp/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(BLENotifyApp.cpp.obj):(.rodata._ZTV17MyServerCallbacks[_ZTV17MyServerCallbacks]+0x14): undefined reference to `BLEServerCallbacks::onConnect(BLEServer*, esp_ble_gatts_cb_param_t*)'

collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.


I know the classes and files are there so how do I tell this to linker, how do I include all my files, so linker will know what to do?

Thanks for Anwsering and Best Regards

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: How to include subcomponents inside ESP-IDF

Postby ESP_Sprite » Thu Apr 18, 2024 12:21 am

You don't need to reference the component files in your main CMakeLists.txt, the component itself needs a CMakeLists.txt that makes esp-idf compile them. Also, your 'component' directory should be in the root of your project, not in the 'main' folder.

Who is online

Users browsing this forum: No registered users and 76 guests