project main file cannot find the component header file ESP32 ESP-IDF VSCode

AnthonyThet
Posts: 11
Joined: Sun Sep 06, 2020 6:46 am

project main file cannot find the component header file ESP32 ESP-IDF VSCode

Postby AnthonyThet » Fri Dec 03, 2021 2:33 am

Hi Everyone, this might be very silly question but I still couldn't be able to overcome this. I am currently working on a product which needs to use a few sensors and transact some data using MQTT and have to use ESP-IDF.
So I just created a sample project in VSCode and created a component library just using "idf.py -C components create-component my_component" command and I just added "my_component.h" in a "main.c" file and try to build but ended up "fatal error: my_component.h: No such file or directory" although all CMakeLists and make file are included.

- sample_project/
- CMakeLists.txt
- sdkconfig
- components/ - my_component/
- CMakeLists.txt
- my_component.c
- include/
- my_component.h
- main/ - CMakeLists.txt
- main.c
- component.mk

- build/

Please let me know if you need to clarify more things about the questions.
Apology for my poor writing skill and thanks so much in advance for your help.

troyduncan
Posts: 3
Joined: Fri Nov 19, 2021 2:59 am

Re: project main file cannot find the component header file ESP32 ESP-IDF VSCode

Postby troyduncan » Sat Dec 04, 2021 1:02 am

In - main/ - CMakeLists.txt you should have something like the following :

Code: Select all

idf_component_register(SRCS "main.c"
                  INCLUDE_DIRS "."
                  PRIV_REQUIRES my_component)
or

Code: Select all

                
set(includedirs
  ../components/my_component/include/
  "."    # this line is probably not needed since main dir is included by default and there are no sub-directories under main
  )

idf_component_register(SRCS "main.c"
                    INCLUDE_DIRS ${includedirs} 
                    PRIV_REQUIRES my_component)

AnthonyThet
Posts: 11
Joined: Sun Sep 06, 2020 6:46 am

Re: project main file cannot find the component header file ESP32 ESP-IDF VSCode

Postby AnthonyThet » Mon Dec 06, 2021 12:43 am

Hi @troyduncan, noted and thanks so much for your reply. It worked and thanks so much again for your prompt response...

Who is online

Users browsing this forum: Bryght-Richard and 110 guests