Our project layout:
/components
----/wifi
--------/include
------------dns.h < this is the file that tries to include the common.h
--------/src
--------CMakeLists.txt
----/common
--------/include
------------common.h
--------/src
------------common.c
--------CMakeLists.txt
/src
----main.c
----CMakeLists.txt
When I go to include files from the component by writing,
#include "common/common.h"
the linker is unable to find the file and says that it doesn’t exist.
However, I know that the common component is being built since the CMake logs show the following line (which if you scroll you can see common is built):
Component names: soc log heap freertos vfs newlib esp_ringbuf driver tcpip_adapter esp_event partition_table app_update spi_flash mbedtls micro-ecc bootloader_support efuse xtensa-debug-module app_trace ethernet nvs_flash pthread smartconfig_ack wpa_supplicant espcoredump esp32 cxx common ota wifi amazon-freertos-common secure_sockets esp_http_server freertos_plus_tcp bootloader nimble bt console esp_adc_cal esptool_py expat wear_levelling sdmmc fatfs freemodbus lwip nghttp openssl spiffs ulp
This shows all of the components being compiled and on the next line it also shows the paths for each of those components - I didn’t copy & paste that for brevity.
My src/CMakeLists.txt
add_compile_options(-w)
cmake_minimum_required(VERSION 3.13)
project(freertos_examples)
add_executable(esp32_app src/main.c)
# Tell IDF build to link against this target.
set(IDF_PROJECT_EXECUTABLE esp32_app)
# Add some extra components. IDF_EXTRA_COMPONENT_DIRS is an variable used by ESP-IDF
# to collect extra components.
get_filename_component(EXTRA_COMPONENT_DIRS components ABSOLUTE)
# Add some external components to the project
set(IDF_EXTRA_COMPONENT_DIRS ${EXTRA_COMPONENT_DIRS})
# As of now there's no offical way to redefine config files outside of Amazon FreeRTOS source tree.
# This is a temporary approach to inject an include path so that this takes precedence over the
# config file directory inside Amazon FreeRTOS.
include_directories(BEFORE amazon-freertos-configs)
# Add amazon freertos as an subdirectory. AFR_BOARD tells which board to target.
set(AFR_BOARD espressif.esp32_devkitc CACHE INTERNAL "")
add_subdirectory(amazon-freertos)
target_link_libraries(esp32_app PRIVATE AFR::demo_mqtt)
target_link_libraries(esp32_app PRIVATE 3rdparty::lwip)
Wifi & Common Component CMakeLists.txt
# include paths of this components.
set(COMPONENT_ADD_INCLUDEDIRS include)
# source files of this components.
set(COMPONENT_SRCDIRS src)
# add this component, this will define a CMake library target.
register_component()
target_link_libraries(${COMPONENT_TARGET} PRIVATE AFR::wifi)
target_link_libraries(${COMPONENT_TARGET} PRIVATE 3rdparty::lwip)
target_link_libraries(${COMPONENT_TARGET} PRIVATE 3rdparty::lwip_osal)
Solutions I’ve tried:
- Hardcoding a relative path, e.g.
#include "../../common/include/common.h"
This does work but is less than ideal, especially with many header files.
I’ve spent quite a bit of time on this and am not sure how to actually include the files. I was hoping to get some help with this issue. Please let me know if any more information or context is required. Also, just as a final note, this is not the first time I am compiling my project. I have made other components and had them work fine, so I don’t think its a set up issue or an issue related to the CMake command I am running.
Thanks!
Compiler & CMake Info
Note: I’m using CLion
CMake Command:
/usr/local/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DAFR_ENABLE_LWIP=1 -DCMAKE_TOOLCHAIN_FILE=amazon-freertos/tools/cmake/toolchains/xtensa-esp32.cmake -GNinja /Users/vp/esp/Pebble_ESP32_Firmware
– The C compiler identification is GNU 5.2.0
– The CXX compiler identification is GNU 5.2.0
AmazonFreertos Version
I have the latest commit on the master branch
amazon-freertos @ 45bcc3a