How to link the prebuilt libraries in amazon-freertos repository?

I m using the amazon-freertos v2021912 repository. There I want to link my prebuild library (libalgobsec.a ) which is in the /aws_demos/application_code/ directory.

I m using the xtensa-esp32-elf-gcc8_4_0-esp-2020r3 toolchain and esp32 dev kit,
I link the library in one of my custom repo where I m using amazon-freertos as an external library. There I know which CMake file is responsible for the build.
So, I added two lines to link the library.

# Declaring the precompiled BSEC lib as imported global so that it doesn't need to be recompiled
add_library(bme680lib STATIC IMPORTED GLOBAL)
set_target_properties(bme680lib PROPERTIES IMPORTED_LOCATION "${PROJECT_SOURCE_DIR}/components/bme680/algo/normal_version/bin/esp/esp32/libalgobsec.a")

# For some reason, math library from newlib isn't implicitly imported so that needs to be manually
# done for now. You might be able to get rid of the hack at some point
add_library(mathlib STATIC IMPORTED GLOBAL)
set_target_properties(mathlib PROPERTIES IMPORTED_LOCATION "${PROJECT_SOURCE_DIR}/amazon-freertos/vendors/espressif/esp-idf/components/newlib/lib/libm.a")


But I m don’t know how will link here.

Hi. I’m not following what you’re saying very well. I am aware of this repo which shows an ESP32 cmake project using amazon freertos as an external library: GitHub - shubhamkulkarni97/amazon-freertos-examples at feature/idf_v4.2 . I hope that helps. If not, perhaps you could explain which cmake files you’re modifying and what result you’re expecting.

I m was trying to link the bosec bme680 prebuilt library( libalgobsec.a). My all programming files are in the aws_demos/application folder. I was trying to link this pre-build library with the bme680 programming file. My prebuild library directory is aws_demos/application_code/bme680/algo/normal_version/bin/esp/esp32 and I m using the esp32-devkit.
So, my question is how should I link this prebuilt library here?

I tried in one of my repositories where I m using the amazon-freertos as the external library and there I m able to link this prebuilt library.
But I don’t know how to link the pre-built when I m not using the amazon-freertos as the external library.


If your application code is based of amazon freertos repository, then the target is defined in the corresponding vendor’s boards CMakeFile. For example ESP32 target is defined here:

Target name by default is aws_demos. You can link the prebuilt static library to the target using cmake function as follows:

add_library(<library name> STATIC IMPORTED)
set_property(TARGET <library name> PROPERTY IMPORTED_LOCATION <location>)
target_link_libraries( <target> <library name>)

More documentation on imported targets can be found here:

Thanks, @ravibhagavandas for your reply.
I m using the esp32 board.

I tried as per your suggestion.

My prebuilt library is in aws_demos/aplication_code/esp32/libalgobsec.a directory.
any the files which uses the lib is in /application_code/ directory.

I changes the cmake file in /application_code/CmakeList.txt directory.
I add the following lines there

add_library(bme680lib STATIC IMPORTED GLOBAL)

set_target_properties(bme680lib PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/esp32/libalgobsec.a")

target_link_libraries(${exe_target} PRIVATE bme680lib )

Still, it’s not able to link the library.
Also i tried
target_link_libraries(aws_demos PRIVATE bme680lib )

What do you mean by not being able to link the library? Do you get an error? In addition to linking the library, you must also include the directory containing the bsec headers to the target.