OTA "No such file or directory"

I’m trying to follow the instructions from the “Using Amazon FreeRTOS in Your Own CMake Project for ESP32” section of the following webpage to link the FreeRTOS OTA code to my code, and some Arduino libraries that I’ve used in my application, but I’m getting “No such file or directory” errors when I try to run CMake. Is there some flag I need to set to link in the OTA files? Or besides “hard coding” the “#include” definitions, what should I check/change?

https://docs.aws.amazon.com/freertos/latest/userguide/getting_started_espressif.html#getting_started_espressif_cmake_project

Hi @Tom, can you provide the complete CMake build logs as well as the directory structure of your CMake Project for us to better understand the problem?

A “No such file or directory” error arises from absence of the header include path in the CMake project. Can you clarify whether these errors are only for the OTA-specific header files OR for other files?
Have you linked AFR::ota to your custom application target using target_link_libraries( PRIVATE AFR::mqtt)?

CMake_Log.h (12.8 KB) CMakeLists.h (1.7 KB)

Hi, Sorry for the delay!

Attached should be the CMake log and my CMakeLists.txt file that have the “.h” extension so I could upload them to you.

My build directory structure is;

amazon-freertos
build
src
esp32
CMakeLists.txt

where the esp32 directory contains some basic Arduino libraries.

As can be seen in the “log”, the problem I’m having is with linking to FreeRTOSConfig.h and sdhconfig.h. I could “hard code” these in the include statment, but there’s 22 versions of FreeRTOSConfig.h in your FreeRTOS library, so I don’t know which one to use.

The Arduino library in esp32 had some “includes” for “FreeRTOS.h” that I did “hard code” the location and those errors went away.

As can be seen in the CMakeLists file, I have the following lines to attempt to link ota and mqtt to my application.

target_link_libraries(h2o_app PRIVATE AFR::demo_ota)
target_link_libraries(h2o_app PRIVATE AFR::demo_mqtt)

Please let me know if you need anything else, or what I should do next to try to resolve this issue.

Thank you!

Tom

Hi @Tom,

Thank you for sharing the CMake logs, and your CMakeLists.txt file.

The build logs show that the failure occurs for the testOTA target build, but the CMakeLists.txt shows that h20_app has been configured to be linked against IDF (instead of the testOTA target).

IDF only allows building against a single executable in the CMake configuration instead of multiple executables.
My recommendation is that if you need the 2 separate executables in your CMake infrastructure, you can utilize a configuration switch to choose the target to build against IDF. Here is an example (by taking target configuration from your CMakeLists.txt)

if( DEFINED BUILD_H20_APP )
    # Build configuration for h20_app
   add_executable(h2o_app src/main.cpp)

   # Set h20_app as the target to link against IDF
    set( (IDF_PROJECT_EXECUTABLE  h20_app)

   target_link_libraries(h2o_app PRIVATE AFR::demo_ota)
   target_link_libraries(h2o_app PRIVATE AFR::demo_mqtt)

else
    file(GLOB ESP32_CODE "src/*.cpp" "src/esp32/*.cpp" "src/esp32/*.c")
    add_executable(testOTA ${ESP32_CODE})

    include_directories("/src/esp32")
    # Set testOTA as the target to link against IDF
    set( (IDF_PROJECT_EXECUTABLE  testOTA)
endif()

When target is configured to build with IDF, this is the include path of FreeRTOSConfig.hin the FreeRTOS code that is used for Epsressif boards. The path is configured by the esp32_devkit.cmake present under the vendors/espressif parent directory.

Hope that helps.

Great! That took care of my “No such file” issue. Thank you!

BUT, now I have the following problem which occurs when I try to call the OTA demo code from my “main.cpp” code. Do you have any recommendations on calling the OTA code to be able to get “vStartOTAUpdateDemoTask” to link in the iot_demo_runner.h file? Or any recommendations on what to check next? The only include statement in the iot_demo_runner.h file is the aws_demo_config.h file which doesn’t “declare” “vStartOTAUpdateDemoTask”, so I don’t understand how the iot_demo_runner.h file would “find it”.

In file included from …/src/main.cpp:83:0:
…/src/main.cpp: In function ‘void setup()’:
…/amazon-freertos/demos/include/iot_demo_runner.h:86:45: error: ‘vStartOTAUpdateDemoTask’ was not declared in this scope
#define DEMO_entryFUNCTION vStartOTAUpdateDemoTask
^
…/src/main.cpp:275:40: note: in expansion of macro ‘DEMO_entryFUNCTION’
.demoFunction = DEMO_entryFUNCTION,
^
[10/68] Building C object amazon-freertos/CMakeFiles/afr_ota.dir/libraries/freertos_plus/aws/ota/src/http/aws_iot_ota_http.c.obj
ninja: build stopped: subcommand failed.

Hi @Tom,

I am happy to know that the header include file path issue is resolved for you!

Regarding the build error with vStartOTAUpdateDemoTask you are seeing, you provided would need to provide a generic declaration for the DEMO_entryFunction-like functions (of which vStartOtaUpdateTask is one).

For reference, the iot_demo_runner.c file in our repository forward declares it here: https://github.com/aws/amazon-freertos/blob/master/demos/demo_runner/iot_demo_runner.c#L46-L51

Providing the above declaration in your main.cpp should fix the build error about function not being declared.

Hope that helps.

Thanks again for the helpful reply!

So I’m now getting “undefined reference to” the following functions in my main.cpp file even though I have “#included” the “.h” files they are defined in.

	runDemoTask					defined in aws_demo.h
	xLoggingTaskInitialize				defined in iot_logging_task.h
	Iot_CreateDetachedThread			defined in iot_threads.h
	xLoggingTaskInitialize				defined in iot_logging_task.h
	vStartOTAUpdateDemoTask		defined in iot_demo_runner.h

Also, I only found the following two functions in the “freertos_hooks.c” file by am not clear how to get them “linked” to my cpp main file.
esp_vApplicationTickHook defined in freertos_hooks.c
esp_vApplicationIdleHook defined in freertos_hooks.c

Any recommendations on what I should check/try?

Hi @Tom ,

Can you confirm that you have linked the executable target against AFR::demo_ota? Linking against it should bring in the definitions of these symbols as linking dependencies.

From the CMakeLists.txt file you had shared earlier, the testOTA executable didn’t have linking dependency with the AFR::demo_otalibrary target.

If that doesn’t fix, please share your updated CMakeLists.txt and build logs for us to take a closer look.

CMakeLists3.h (2.0 KB) Gmake_Log3.h (173.7 KB)

By “linking dependency with the AFR::demo_ota library target” do you mean the following? ( Which is in my Gmake file that should be attached, along with the log )

As shown, I’ve tried both “demo_ota” and “ota”.

target_link_libraries(h2o_app PRIVATE AFR::demo_ota)
target_link_libraries(h2o_app PRIVATE AFR::demo_mqtt)

target_link_libraries(h2o_app PRIVATE AFR::ota)

target_link_libraries(h2o_app PRIVATE AFR::mqtt)

Again, thank you for your help!

The text in large font had a “#” in front of it that caused the large text. As can be seen in the Cmake file, these lines were “commented out” with the #.

Wasn’t sure if I should have both “target_link_libraries” for ota and mqtt to get the ota demo to run ( as shown above ), so I commented out the mqtt and now all the errors previously listed aren’t shown, but now I’m getting “No such file or directory” errors between the FreeRTOS library code.

So should I have BOTH “target_link_libraries”? And if so, are there any other ones I should have?

If I should have only the “ota” target_link_library, what is the best way to resolve this “linking issue”?

In the CMakeLists,txt file that is in the “amazon-freertos/vendors/espressif/boards/esp32” directory, there are multiple “target_include_directories” and “target_link_libraries” specified. Should I be doing something similar? I’ve never used CMake before, so maybe “example code” of how I should do this would be great ( if possible ) as I really don’t understand ( at least yet ) the one in the esp32 directory.

Hi,

I just tried this in my example repo and it worked, https://github.com/tgsong/amazon-freertos-examples, this is what I changed,

Let me know if this helps,
Thanks

Hi tiangs,

Thanks for the reply! But I’m a bit confused, isn’t the following statements ( that I showed in the previous posts above ) what you’re asking me to try in my “main” CMakeList.txt file?

target_link_libraries(h2o_app PRIVATE AFR::demo_ota)
target_link_libraries(h2o_app PRIVATE AFR::demo_mqtt)

I also have set the line to the OTA demo in the aws_demo_config.h file.

I’m still getting either “No such file” errors or “undefined reference” errors.

From your “examples” website, in your “Troubleshooting” section you mention adding “target_link_link_libraries to your application target”. Would that be the same “format” as the

target_link_libraries( afr_demo PRIVATE AFR::demo_mqtt)

line 29 in your link above into my “top level” CMakeList.txt file?