I would like to include pre-built component library in my project, but directory level is required to be one level above the project’s root directory containing the platformio.ini. But it returns error saying that "undefined reference to `init_iaq_2nd_gen’ ".
Please see structure below.
components
zmod4xxx (component directory)
project_root
platformio.ini
src
My platformio.ini looks like this.
[env:esp32-s3-devkitc-1]
platform = espressif32
board = esp32-s3-devkitc-1
framework = espidf
I tried to debug with the message,
message(“Linking ${blob} library: ${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}/lib_${blob}.a”).
The message output confirms that the path is correct and the prebuilt library is being linked from the expected location.
Please note that if I include components folder with same level as project root then it compiles without any issue.
So does the linker command contain a wrong -L path to the components/zmod4xxx folder then or a wrong -l<library name> flag? Check the full invocation with project tasks → Advanced → Verbose Build.
For further investigation please see complete CMakeLists.txt below.
idf_build_get_property(idf_target IDF_TARGET)
idf_component_register(
# sources to compile
SRCS src/zmod4xxx.c HAL/zmod4xxx_hal.c
INCLUDE_DIRS include HAL lib/esp32s3
REQUIRES driver i2cdev log
)
idf_build_get_property(build_dir BUILD_DIR)
set(target_name "${idf_target}")
# This sets the link directory for the COMPONENT_LIB.
# It's specifying a directory where linker libraries for the component will be found
target_link_directories(${COMPONENT_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}")
# adding a prebuilt library for iaq_2nd_gen
set(blob iaq_2nd_gen)
add_prebuilt_library(${blob} "${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}/lib_${blob}.a"
REQUIRES ${COMPONENT_NAME})
# This links the ${blob} library to the COMPONENT_LIB
message("Linking ${blob} library: ${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}/lib_${blob}.a")
target_link_libraries(${COMPONENT_LIB} PUBLIC ${blob})
# adding a prebuilt library for zmod4xxx_cleaning
set(blobcleaning zmod4xxx_cleaning)
add_prebuilt_library(${blobcleaning} "${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}/lib_${blobcleaning}.a"
REQUIRES ${COMPONENT_NAME})
# This links the ${blob1} library to the COMPONENT_LIB
target_link_libraries(${COMPONENT_LIB} PUBLIC ${blobcleaning})
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
I’m a bit confused, a CMakeLists.txt is for ESP-IDF components, but lib_extra_dirs = ... is for the PlatformIO library system. A library in the PlatformIO library system is added to the build per its library.json specifications (if such a file exists at all), not according to the CMakeLists.txt, that would be ignored. Specifically, libaries added via lib_deps/lib_extra_dirs are not evaluated as ESP-IDF components by the CMake build system (see issue).
I’d suggest removing the lib_extra_dirs line from the platformio.ini and only going through the CMake build system by declaring ../components as a to-be-added extra component dir using
@maxgerhardt Thank you for clarification.
I removed …/components from platformio.ini, but I keep other needed folders in platformio.ini as below.
lib_extra_dirs =
…/…/common/esp-idf-lib/components
…/…/common/components
…/common
Is it correct? or if once I use CMake build system, then shall I remove all of them?
@maxgerhardt
Hello, Please confirm if I declare extra component dir using list(APPEND EXTRA_COMPONENT_DIRS ../components), then I can not use other components which defined in the lib_deps/lib_extra_dirs of platformio.ini.
I mean is it possible to use two different components (one is declared in the CMakeLists.txt, and another from platformio.ini lib_deps /lib_extra_dirs) simultaneously in one project.
Thank you and best regards
Lhagva