Needed to create own shared library in freertos / amazon freertos, any help is highly appreciated

I wanted to create a shared / static library with my code that is written with amazon freertos and building successful. but unable to make it as library with cross-compiling for esp32.
while using add_library( ) with CMakeLists.txt it shows error to not found files of Freertos.h etc.

Any help or lead is highly appreciated.

Assuming GCC.

Can you show the command lines you used. Normally I would use the same compiler options (so there should be no difference in the include paths between creating an executable image and a static library) to build object files, using the -c option to GCC so the compiler stops at the object file. Then rather than using ld to link the object files into an executable file (or elf probably) I would use ar to place all the object files into an archive.

I am cross compiling the project for xtensa, and it is gcc based i hope.

Using below CMakeLists.txt file

--------------------------------------------
cmake_minimum_required(VERSION 3.13)

project(afr_gen)

include_directories( ${PROJECT_SOURCE_DIR}/src/app/common/
	${PROJECT_SOURCE_DIR}/src/app/gen/
	${PROJECT_SOURCE_DIR}/src/drivers/esp32/hal/
	${PROJECT_SOURCE_DIR}/src/platform/board/
)

file(GLOB afr_gen_SRC
#	"${PROJECT_SOURCE_DIR}/src/app/common/*.h"
#	"${PROJECT_SOURCE_DIR}/src/app/gen/*.h"
#	"${PROJECT_SOURCE_DIR}/src/drivers/esp32/hal/*.h" 
#	"${PROJECT_SOURCE_DIR}/src/platform/board/*.h"
	"${PROJECT_SOURCE_DIR}/freertos/libraries/abstractions/posix/include/FreeRTOS_POSIX/time.h"
#	"${PROJECT_SOURCE_DIR}/src/platform/esp32/*.h"
#	"${PROJECT_SOURCE_DIR}/src/platform/freertos/*.h"
	"${PROJECT_SOURCE_DIR}/src/app/common/*.c"
	"${PROJECT_SOURCE_DIR}/src/app/gen/*.c"
	"${PROJECT_SOURCE_DIR}/src/drivers/esp32/hal/*.c" 
	"${PROJECT_SOURCE_DIR}/src/platform/board/*.c"
)

set(exe_target afr_gen)
set(linker_flags "-Wl,--gc-sections" "-Wl,--cref" "-Wl,--Map=${exe_target}.map" "-Wl,--undefined=uxTopUsedPriority")

set(CMAKE_EXECUTABLE_SUFFIX ".elf")
add_executable(afr_gen ${afr_gen_SRC})
add_library(pnrTest 
    MODULE
    ${afr_gen_SRC})

# Tell IDF build to link against this target.
set(IDF_PROJECT_EXECUTABLE afr_gen)

include_directories(BEFORE config)

# Add FreeRTOS as a subdirectory. AFR_BOARD tells which board to target.
set(AFR_BOARD espressif.esp32_devkitc CACHE INTERNAL "")
add_subdirectory(freertos)

# Link against the mqtt library so that we can use it. Dependencies are transitively
# linked.
target_link_libraries(afr_gen PRIVATE AFR::crypto AFR::pkcs11 AFR::utils AFR::wifi AFR::ble AFR::ble_wifi_provisioning AFR::ota AFR::device_shadow AFR::core_mqtt AFR::core_json AFR::secure_sockets AFR::transport_interface_secure_sockets AFR::backoff_algorithm)

--------------------------------------------

Command is :
cmake -S . -B build -DIDF_SDKCONFIG_DEFAULTS=/home/naresh/dev_n/lib_test/CMakeT/config/sdkconfig -DCMAKE_TOOLCHAIN_FILE=freertos/tools/cmake/toolchains/xtensa-esp32.cmake

please provide some help on same.

If the build system doesn’t already provide a mechanism to create an archive (I don’t have the docs for it), then you will have to edit the files to add that in. I can see a linker command line there which is presumably creating the executable, so guess you need something similar for the archiver.

… also I’m not aware of any shared library / dynamic linking support for deeply embedded systems especially when running from flash. If you really need a FreeRTOS as library then use a static one.