[SOLVED] Creating custom component need help

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

[SOLVED] Creating custom component need help

Postby zazas321 » Wed Aug 11, 2021 8:52 am

Hello. I am trying to create custom component for my esp-idf project. I have started off with hello_world example and in my project folder I have created components folder. In my components folder I have place my .c and .h files as well as CMakeLists.txt.
See the image for my project structure:
https://ibb.co/z5h9XFn



I am now just trying to get test component to work. Forget about https_ota


So as you can see from the image, in my components/test folder I have 3 files:
1. test.c
2. test.h
3. CMakeLists.txt

In my test.c:

Code: Select all

#include "test.h"

void test_printf(){
    printf("hello world from test file");
}

In my test.h:

Code: Select all

void test_printf();
In my CMakeLists.txt:

Code: Select all

idf_component_register(SRCS "test.c"
                    INCLUDE_DIRS "")

                   

All I am trying to do now, is to include "test.h" in my main.c and use this test_printf function in my main.c

Trying to include "test.h" in my main.c gives an error:

Code: Select all

> Executing task: cmake --build . <

[1/8] Performing build step for 'bootloader'
ninja: no work to do.
[2/6] Building C object esp-idf/main/CMakeFiles/__idf_main.dir/hello_world_main.c.obj
FAILED: esp-idf/main/CMakeFiles/__idf_main.dir/hello_world_main.c.obj 
C:\Users\petrikas.lu\.espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-gcc.exe -DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -Iconfig -IC:/Users/petrikas.lu/esp/esp-idf/components/newlib/platform_include -IC:/Users/petrikas.lu/esp/esp-idf/components/freertos/include -IC:/Users/petrikas.lu/esp/esp-idf/components/freertos/port/xtensa/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_hw_support/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_hw_support/port/esp32/. -IC:/Users/petrikas.lu/esp/esp-idf/components/heap/include -IC:/Users/petrikas.lu/esp/esp-idf/components/log/include -IC:/Users/petrikas.lu/esp/esp-idf/components/lwip/include/apps -IC:/Users/petrikas.lu/esp/esp-idf/components/lwip/include/apps/sntp -IC:/Users/petrikas.lu/esp/esp-idf/components/lwip/lwip/src/include -IC:/Users/petrikas.lu/esp/esp-idf/components/lwip/port/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/lwip/port/esp32/include/arch -IC:/Users/petrikas.lu/esp/esp-idf/components/soc/include -IC:/Users/petrikas.lu/esp/esp-idf/components/soc/esp32/. -IC:/Users/petrikas.lu/esp/esp-idf/components/soc/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/hal/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/hal/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_rom/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_rom/esp32 -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_common/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_system/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/driver/include -IC:/Users/petrikas.lu/esp/esp-idf/components/driver/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_ringbuf/include -IC:/Users/petrikas.lu/esp/esp-idf/components/efuse/include -IC:/Users/petrikas.lu/esp/esp-idf/components/efuse/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/xtensa/include -IC:/Users/petrikas.lu/esp/esp-idf/components/xtensa/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/espcoredump/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_timer/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_ipc/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_pm/include -IC:/Users/petrikas.lu/esp/esp-idf/components/vfs/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_wifi/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_wifi/esp32/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_event/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_netif/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_eth/include -IC:/Users/petrikas.lu/esp/esp-idf/components/tcpip_adapter/include -IC:/Users/petrikas.lu/esp/esp-idf/components/app_trace/include -IC:/Users/petrikas.lu/esp/esp-idf/components/mbedtls/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/mbedtls/mbedtls/include -IC:/Users/petrikas.lu/esp/esp-idf/components/mbedtls/esp_crt_bundle/include -IC:/Users/petrikas.lu/esp/esp-idf/components/app_update/include -IC:/Users/petrikas.lu/esp/esp-idf/components/spi_flash/include -IC:/Users/petrikas.lu/esp/esp-idf/components/bootloader_support/include -IC:/Users/petrikas.lu/esp/esp-idf/components/nvs_flash/include -IC:/Users/petrikas.lu/esp/esp-idf/components/pthread/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_gdbstub/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_gdbstub/xtensa -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_gdbstub/esp32 -IC:/Users/petrikas.lu/esp/esp-idf/components/wpa_supplicant/include -IC:/Users/petrikas.lu/esp/esp-idf/components/wpa_supplicant/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/wpa_supplicant/include/esp_supplicant -IC:/Users/petrikas.lu/esp/esp-idf/components/perfmon/include -IC:/Users/petrikas.lu/esp/esp-idf/components/asio/asio/asio/include -IC:/Users/petrikas.lu/esp/esp-idf/components/asio/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/cbor/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/unity/include -IC:/Users/petrikas.lu/esp/esp-idf/components/unity/unity/src -IC:/Users/petrikas.lu/esp/esp-idf/components/cmock/CMock/src -IC:/Users/petrikas.lu/esp/esp-idf/components/coap/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/coap/port/include/coap -IC:/Users/petrikas.lu/esp/esp-idf/components/coap/libcoap/include -IC:/Users/petrikas.lu/esp/esp-idf/components/coap/libcoap/include/coap2 -IC:/Users/petrikas.lu/esp/esp-idf/components/console -IC:/Users/petrikas.lu/esp/esp-idf/components/nghttp/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/nghttp/nghttp2/lib/includes -IC:/Users/petrikas.lu/esp/esp-idf/components/esp-tls -IC:/Users/petrikas.lu/esp/esp-idf/components/esp-tls/esp-tls-crypto -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_adc_cal/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_hid/include -IC:/Users/petrikas.lu/esp/esp-idf/components/tcp_transport/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_http_client/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_http_server/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_https_ota/include -IC:/Users/petrikas.lu/esp/esp-idf/components/protobuf-c/protobuf-c -IC:/Users/petrikas.lu/esp/esp-idf/components/protocomm/include/common -IC:/Users/petrikas.lu/esp/esp-idf/components/protocomm/include/security -IC:/Users/petrikas.lu/esp/esp-idf/components/protocomm/include/transports -IC:/Users/petrikas.lu/esp/esp-idf/components/mdns/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_local_ctrl/include -IC:/Users/petrikas.lu/esp/esp-idf/components/sdmmc/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_serial_slave_link/include -IC:/Users/petrikas.lu/esp/esp-idf/components/esp_websocket_client/include -IC:/Users/petrikas.lu/esp/esp-idf/components/expat/expat/expat/lib -IC:/Users/petrikas.lu/esp/esp-idf/components/expat/port/include -IC:/Users/petrikas.lu/esp/esp-idf/components/wear_levelling/include -IC:/Users/petrikas.lu/esp/esp-idf/components/fatfs/diskio -IC:/Users/petrikas.lu/esp/esp-idf/components/fatfs/vfs -IC:/Users/petrikas.lu/esp/esp-idf/components/fatfs/src -IC:/Users/petrikas.lu/esp/esp-idf/components/freemodbus/common/include -IC:/Users/petrikas.lu/esp/esp-idf/components/idf_test/include -IC:/Users/petrikas.lu/esp/esp-idf/components/idf_test/include/esp32 -IC:/Users/petrikas.lu/esp/esp-idf/components/jsmn/include -IC:/Users/petrikas.lu/esp/esp-idf/components/json/cJSON -IC:/Users/petrikas.lu/esp/esp-idf/components/libsodium/libsodium/src/libsodium/include -IC:/Users/petrikas.lu/esp/esp-idf/components/libsodium/port_include -IC:/Users/petrikas.lu/esp/esp-idf/components/mqtt/esp-mqtt/include -IC:/Users/petrikas.lu/esp/esp-idf/components/openssl/include -IC:/Users/petrikas.lu/esp/esp-idf/components/spiffs/include -IC:/Users/petrikas.lu/esp/esp-idf/components/ulp/include -IC:/Users/petrikas.lu/esp/esp-idf/components/wifi_provisioning/include -mlongcalls -Wno-frame-address   -ffunction-sections -fdata-sections -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -Og -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -std=gnu99 -Wno-old-style-declaration -D_GNU_SOURCE -DIDF_VER=\"v4.3-dirty\" -DESP_PLATFORM -MD -MT esp-idf/main/CMakeFiles/__idf_main.dir/hello_world_main.c.obj -MF esp-idf\main\CMakeFiles\__idf_main.dir\hello_world_main.c.obj.d -o esp-idf/main/CMakeFiles/__idf_main.dir/hello_world_main.c.obj   -c ../main/hello_world_main.c
../main/hello_world_main.c:18:10: fatal error: test.h: No such file or directory
 #include "test.h"
          ^~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command cmake --build ." terminated with exit code: 1.

ESP_Minatel
Posts: 364
Joined: Mon Jan 04, 2021 2:06 pm

Re: Creating custom component need help

Postby ESP_Minatel » Wed Aug 11, 2021 9:46 am

Hi,

Have you tried to create the new component by the following command?

Code: Select all

idf.py create-component <components/comp_name>
You can try by this way to create new components for your project.

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

Re: Creating custom component need help

Postby zazas321 » Wed Aug 11, 2021 10:29 am

I dont have any clue how do i use idf.py commands. I do everything from visual studio code.
I have tried to run this command on terminal and got error:
'idf.py' is not recognized as an internal or external command,

But I assume it does exactly the same as I have did. It jus creates component directory if its not created and then places my component in there which is exactly what I have done.


According to the documentation, there should be nothing else needed to do

ESP_Minatel
Posts: 364
Joined: Mon Jan 04, 2021 2:06 pm

Re: Creating custom component need help

Postby ESP_Minatel » Wed Aug 11, 2021 11:06 am

You need to add the "." for the includes.

Code: Select all

idf_component_register(SRCS "test.c"
                    INCLUDE_DIRS ".")

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

Re: Creating custom component need help

Postby zazas321 » Wed Aug 11, 2021 11:07 am

Oh my gosh that actually works. Cant believe you have spotted this error! Thank you for saving me

Who is online

Users browsing this forum: Baidu [Spider] and 75 guests