diff --git a/CMakeLists.txt b/CMakeLists.txt index abd032e3e30..4abc4ab52f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -519,7 +519,11 @@ target_link_libraries(executorch_core PRIVATE program_schema) if(ANDROID) target_link_libraries(executorch_core PUBLIC log) endif() -if(EXECUTORCH_USE_DL) +# Skip when cross-compiling: find_library() resolves the host libdl even for a +# bare-metal target (e.g. arm-none-eabi), which then links -ldl into the +# baremetal runner and fails ("cannot find -ldl"). dladdr() isn't used on those +# targets anyway. Per-target presets also set EXECUTORCH_USE_DL OFF explicitly. +if(EXECUTORCH_USE_DL AND NOT CMAKE_CROSSCOMPILING) # Check if dl exists for this toolchain and only then link it. find_library(DL_LIBRARY_EXISTS NAMES dl) # Check if the library was found diff --git a/tools/cmake/preset/arm_baremetal.cmake b/tools/cmake/preset/arm_baremetal.cmake index c12cc95233a..cb39de6945e 100644 --- a/tools/cmake/preset/arm_baremetal.cmake +++ b/tools/cmake/preset/arm_baremetal.cmake @@ -29,6 +29,8 @@ set_overridable_option(EXECUTORCH_BUILD_EXECUTOR_RUNNER OFF) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR OFF) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER OFF) set_overridable_option(EXECUTORCH_BUILD_ARM_BAREMETAL ON) +# Bare-metal has no libdl (see CMakeLists.txt EXECUTORCH_USE_DL block). +set_overridable_option(EXECUTORCH_USE_DL OFF) set_overridable_option(EXECUTORCH_BUILD_KERNELS_QUANTIZED ON) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL ON) set_overridable_option(EXECUTORCH_BUILD_CORTEX_M ON) diff --git a/tools/cmake/preset/esp_baremetal.cmake b/tools/cmake/preset/esp_baremetal.cmake index 3df77586d1d..8935b6f2fe7 100644 --- a/tools/cmake/preset/esp_baremetal.cmake +++ b/tools/cmake/preset/esp_baremetal.cmake @@ -7,6 +7,8 @@ set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}") set_overridable_option(EXECUTORCH_BUILD_EXECUTOR_RUNNER OFF) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR OFF) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER OFF) +# Bare-metal has no libdl (see CMakeLists.txt EXECUTORCH_USE_DL block). +set_overridable_option(EXECUTORCH_USE_DL OFF) set_overridable_option(EXECUTORCH_BUILD_KERNELS_QUANTIZED ON) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL ON) set_overridable_option(EXECUTORCH_ENABLE_LOGGING ON) diff --git a/tools/cmake/preset/zephyr.cmake b/tools/cmake/preset/zephyr.cmake index 651e3e0b3c6..69a39bbad71 100644 --- a/tools/cmake/preset/zephyr.cmake +++ b/tools/cmake/preset/zephyr.cmake @@ -6,6 +6,8 @@ set_overridable_option(EXECUTORCH_BUILD_COREML OFF) set_overridable_option(EXECUTORCH_ENABLE_EVENT_TRACER OFF) +# Bare-metal has no libdl (see CMakeLists.txt EXECUTORCH_USE_DL block). +set_overridable_option(EXECUTORCH_USE_DL OFF) set_overridable_option(EXECUTORCH_BUILD_KERNELS_LLM OFF) set_overridable_option(EXECUTORCH_BUILD_KERNELS_LLM_AOT OFF) set_overridable_option(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER OFF)