1
votes

I am developing a project for the ESP32 using ESP-IDF. I am trying to use the Bluetooth libraries inside a component, but the compiler complains that the header file does not exist. Including the same header file from main.c works without any problems. The header files I'm trying to include are:

#include "esp_bt.h"
#include "esp_bt_main.h"
#include "esp_gatts_api.h"
#include "esp_gap_ble_api.h"
#include "esp_gatt_common_api.h"

Is there any reason why there are certain header files that can only be included from main.c? Is there any solution or does one have to put certain functionality in the main.c file to appease ESP-IDF?

Note: I have the same problem with including header files when trying to use HTTPS Server.

In case it's of any relevance this is the project structure I'm using:

- CMakeLists.txt
- Makefile
- sdkconfig
- main
    - CMakeLists.txt
    - component.mk
    - main.c
- components
    - component1
        - component1.h
        - component1.c
        - CMakeLists.txt

The CMakeLists.txt files are all identical:

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

The main function is a very simple function that sets up the environment (eg. NVS_FLASH) and calls each component's setup function and terminates, leaving control of the program to the components.

2
how you can't include them? - Juraj
Sure I can write #include "whatever.h", but when compiling the compiler complains that the header doesn't exist. This error only comes up if I include the headers from a components file and not the main.c file. I'll edit the question to make it more clear. - theHoatzin
do you have component.mk in component1? - Juraj
Yes, you should definitely be able to include the files from any place. I'm not 100% familiar with the build system mechanics, but could you try to add a REQUIRES bt to your idf_component_register, like this: idf_component_register(SRCS "ble.c" INCLUDE_DIRS "." REQUIRES bt)? - StrawHat
@theHoatzin what commands do you use to build the project? What is your IDF version? - StrawHat

2 Answers

3
votes

You should definitely be able to include the files from any place. Adding a REQUIRES <component-name> to your idf_component_register command should solve the problem: idf_component_register(SRCS "ble.c" INCLUDE_DIRS "." REQUIRES bt).

This is the general way in IDF to include other components.

1
votes

In command idf.py menuconfig, once you enable Bluetooth (Component config--->Bluetooth--->Bluetooth), these header files will be loaded automatically.