Page 1 of 1

How do I set a SDK as external library?

Posted: Sun Jun 08, 2025 9:56 am
by aero04
Hi all!
I am new to this forum and to ESP32 but programmed microcontrollers in the past.
I want to use an ESP32C6 board to use it as a custom Zigbee device.
To introduce myself to that I successfully downloaded, compiled and programmed my board (using Visual Studio Code and the ESP-IDF extension) with the "HA_on_off_switch" example from the Zigbee SDK (https://github.com/espressif/esp-zigbee-sdk).

Now I want to seperate the Zigbee SDK from the "HA_on_off_switch" example. I want to do this because in the future I will have multiple projects being based on the Zigbee SDK and I don't want to download about 130MB ("managed_components" folder) into every project.

What I did so far:
  • I uncommented the library dependencies in the file "idf_component.yml" of the "main" folder as following to avoid downloading it to the "managed_components" folder everytime:

    Code: Select all

    ## IDF Component Manager Manifest File
    dependencies:
     ## espressif/esp-zboss-lib: "~1.6.0"
     ## espressif/esp-zigbee-lib: "~1.6.0"
     ## espressif/led_strip: "~2.0.0"
      ## Required IDF version
      idf:
        version: ">=5.0.0"
  • I registered these libraries (which are in a folder called "lib") in the "CMakeLists.txt" file of the "main" folder:

    Code: Select all

    string(REPLACE "\\" "/" IDF_PATH  ${IDF_PATH})
    idf_component_register(
        INCLUDE_DIRS "." "C:/Users/USER/Desktop/lib/esp-zigbee-lib/" "C:/Users/USER/Desktop/lib/esp-example-common/" "C:/Users/USER/Desktop/lib/esp-example-common/" "C:/Users/USER/Desktop/lib/esp-zboss-lib/" "C:/Users/USER/Desktop/lib/led_strip/"
    )
  • In the ".vscode" folder of the project I modified the "c_cpp_properties.json" file and added the library folders:

    Code: Select all

    {
        "configurations": [
            {
                "name": "ESP-IDF",
                "compilerPath": "${config:idf.toolsPathWin}\\tools\\xtensa-esp-elf\\esp-14.2.0_20241119\\xtensa-esp-elf\\bin\\xtensa-esp32-elf-gcc.exe",
                "compileCommands": "${config:idf.buildPath}/compile_commands.json",
                "includePath": [
                    "${config:idf.espIdfPath}/components/**",
                    "${config:idf.espIdfPathWin}/components/**",
                    "${workspaceFolder}/**",
                    "C:/Users/USER/Desktop/lib/esp-zboss-lib/",
                    "C:/Users/USER/Desktop/lib/esp-zigbee-lib/",
                    "C:/Users/USER/Desktop/lib/esp-example-common/",
                    "C:/Users/USER/Desktop/lib/led_strip/"
                ],
                "browse": {
                    "path": [
                        "${config:idf.espIdfPath}/components",
                        "${config:idf.espIdfPathWin}/components",
                        "${workspaceFolder}",
                        "C:/Users/USER/Desktop/lib/esp-zboss-lib/",
                        "C:/Users/USER/Desktop/lib/esp-zigbee-lib/",
                        "C:/Users/USER/Desktop/lib/esp-example-common/",
                        "C:/Users/USER/Desktop/lib/led_strip/"
                    ],
                    "limitSymbolsToIncludedHeaders": true
                }
            }
        ],
        "version": 4
    }

My problem now is, that I get these two errors in VSCode:

Code: Select all

#include errors detected. Consider updating your compile_commands.json or includePath. Squiggles are disabled for this translation unit (C:\\Users\\USER\\Desktop\\Zigbee_on_off_light_test\\main\\esp_zb_light.c).
cannot open source file \"portmacro.h\" (dependency of \"C:\\Users\\USER\\.vscode\\extensions\\ms-vscode.cpptools-1.25.3-win32-x64\\bin\\freertos\\FreeRTOS.h\")"
And that the compiling does not finish with the following error:

Code: Select all

[1022/1024] Linking CXX executable Zigbee_on_off_light_test.elf
FAILED: Zigbee_on_off_light_test.elf
C:\WINDOWS\system32\cmd.exe /C "cd . && C:\Users\USER\.espressif\tools\riscv32-esp-elf\esp-14.2.0_20241119\riscv32-esp-elf\bin\riscv32-esp-elf-g++.exe -march=rv32imac_zicsr_zifencei -nostartfiles -march=rv32imac_zicsr_zifencei --specs=nosys.specs    -Wl,--cref -Wl,--defsym=IDF_TARGET_ESP32C6=0 -Wl,--Map=C:/Users/USER/Desktop/Zigbee_on_off_light_test/build/Zigbee_on_off_light_test.map -Wl,--no-warn-rwx-segments -Wl,--orphan-handling=warn -fno-rtti -fno-lto -Wl,--gc-sections -Wl,--warn-common -T rom.api.ld -T esp32c6.peripherals.ld -T esp32c6.rom.ld -T esp32c6.rom.api.ld -T esp32c6.rom.rvfp.ld -T esp32c6.rom.wdt.ld -T esp32c6.rom.systimer.ld -T esp32c6.rom.version.ld -T esp32c6.rom.phy.ld -T esp32c6.rom.coexist.ld -T esp32c6.rom.net80211.ld -T esp32c6.rom.pp.ld -T esp32c6.rom.newlib.ld -T esp32c6.rom.newlib-normal.ld -T esp32c6.rom.heap.ld -T memory.ld -T sections.ld @CMakeFiles\Zigbee_on_off_light_test.elf.rsp -o Zigbee_on_off_light_test.elf && cd ."
C:/Users/USER/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20241119/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/14.2.0/../../../../riscv32-esp-elf/bin/ld.exe: esp-idf/freertos/libfreertos.a(app_startup.c.obj): in function `main_task':
C:/Users/USER/esp/v5.4.1/esp-idf/components/freertos/app_startup.c:206:(.text.main_task+0x76): undefined reference to `app_main'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
How do I fix this error?
Did I do something wrong ar am I missing something concerning the including of the library paths?

Thanks for any help in advance!

Re: How do I set a SDK as external library?

Posted: Mon Jun 09, 2025 8:28 am
by nopnop2002
I don't want to download about 130MB ("managed_components" folder) into every project.

In a bash environment, the following will work:

Code: Select all

$ mv managed_components /home/esp32/lib

$ rm main/idf_component.yml

$ rm main/dependencies.lock

$ edit CMakeLists.txt and add this

set(EXTRA_COMPONENT_DIRS /home/esp32/lib)

$ idf.py build
idf.py uses components from /home/esp32/lib.