diff --git a/tools/cmakev2/build.cmake b/tools/cmakev2/build.cmake index 06c441a5db6..15ed609b487 100644 --- a/tools/cmakev2/build.cmake +++ b/tools/cmakev2/build.cmake @@ -361,11 +361,25 @@ function(idf_build_library library) # Include the requested components and link their interface targets to the # library. + # + # On the GNU linker, bracket the component interface list with + # --start-group/--end-group so the linker re-scans archives until all + # symbols resolve. Required when the archive defining a __wrap_* + # implementation is encountered after the archive consuming the wrapped + # symbol on the link line; without group iteration the wrap symbol is + # unresolved. + idf_build_get_property(linker_type LINKER_TYPE) + if("${linker_type}" STREQUAL "GNU") + target_link_libraries("${library}" INTERFACE "-Wl,--start-group") + endif() foreach(component_name IN LISTS ARG_COMPONENTS) idf_component_include("${component_name}") idf_component_get_property(component_interface "${component_name}" COMPONENT_INTERFACE) target_link_libraries("${library}" INTERFACE "${component_interface}") endforeach() + if("${linker_type}" STREQUAL "GNU") + target_link_libraries("${library}" INTERFACE "-Wl,--end-group") + endif() # Process optional requirements in DEFERRED mode only (no-op in IMMEDIATE or when unset). idf_build_get_property(opt_req_mode IDF_COMPONENT_OPTIONAL_REQUIRES_MODE)