Page 1 of 1

Certain header files can only be imported from main.c

Posted: Wed Jun 24, 2020 2:12 pm
by letsbuild
There are certain header files I can only include from main.c or else the compiler complains that the header file does not exist.
Examples of these header files are:
"nvs_flash.h"
Bluetooth files eg. "esp_bt.h", "esp_bt_main.h"
HTTPS Server files

Is there any reason why these files can only be included from main.c? Is this behavior expected or is the problem related to my project?

My project structure consists of the following structure:
- CMakeLists.txt
- Makefile
- sdkconfig
- main
- CMakeLists.txt
- component.mk
- main.c
- components
- component1
- component1.h
- component1.c
- CMakeLists.txt

Re: Certain header files can only be imported from main.c

Posted: Wed Jun 24, 2020 11:21 pm
by ESP_Angus
Hi letsbuild,

The CMake build system tracks dependencies between components, so components need to declare the other dependencies that they require. "main" component is the one exception to this rule, it automatically requires all the other components.

A full explanation can be found here: https://docs.espressif.com/projects/esp ... quirements

(This seems like a common source of confusion for people setting up their own CMake components for the first time. Is there anywhere that you think this should be mentioned more prominently? If so, please let us know and we will add it.)

Angus

Re: Certain header files can only be imported from main.c

Posted: Wed Jul 01, 2020 9:25 am
by letsbuild
Hey ESP_Angus,

thank you very much for your reply. Adding "REQUIRES bt" to my CMake component fixed the issue.

I think the Build System documentation should contain a list of all possible components that you can REQUIRE.
I think two things could make it more clear:
1) The examples could add the REQUIRES necessary despite them not needing them because they are fully contained in the main component.
2) Having the documentation of each component specify how to include the component in non-main components.

The Build System documentation has a list of components that you do not have to manually add to CMake, but I haven't found a list of the components, and their corresponding name, that you have to add manually. Therefore despite knowing that a component has to be manually installed one might not be able to figure out exactly how to phrase it: should it be "REQUIRES bt" or REQUIRES "bluetooth"?