From b8b2246070efec923f9de3a97ded7a346dca6c3c Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Fri, 21 Aug 2026 21:26:05 -0700 Subject: [PATCH] Link duckdb_generated_extension_loader when linking duckdb statically Homebrew's libduckdb_static.a requires the companion libduckdb_generated_extension_loader.a archive, which provides the init hooks for duckdb's own statically-bundled extensions (json, parquet, icu, autocomplete, core_functions). Without it, statically linking the duckdb extension fails with undefined symbols like duckdb::DuckDB::LoadStaticExtension(). Link the exported duckdb_generated_extension_loader target after ${DuckDB_LIBRARIES} whenever DuckDB_USE_STATIC_LIBS is set, followed by each bundled extension archive listed in DuckDB_EXTENSIONS (order matters: the loader references symbols from both). --- duckdb/CMakeLists.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/duckdb/CMakeLists.txt b/duckdb/CMakeLists.txt index ae8ad804..c31bfdbf 100644 --- a/duckdb/CMakeLists.txt +++ b/duckdb/CMakeLists.txt @@ -25,3 +25,24 @@ build_extension_lib(${BUILD_STATIC_EXTENSION} "duckdb") target_link_libraries(lbug_${EXTENSION_LIB_NAME}_extension PRIVATE ${DuckDB_LIBRARIES}) +if (DuckDB_USE_STATIC_LIBS) + # Statically-linked duckdb requires its generated extension loader archive, + # which provides the init hooks for duckdb's bundled extensions, plus the + # archives of those bundled extensions themselves. Order matters: the + # loader references symbols from both duckdb_static and the extension + # archives, so it must be linked in between. + if (TARGET duckdb_generated_extension_loader) + set(DUCKDB_STATIC_EXTRA_LIBS duckdb_generated_extension_loader) + foreach (duckdb_ext IN LISTS DuckDB_EXTENSIONS) + if (TARGET "${duckdb_ext}_extension") + list(APPEND DUCKDB_STATIC_EXTRA_LIBS "${duckdb_ext}_extension") + endif () + endforeach () + target_link_libraries(lbug_${EXTENSION_LIB_NAME}_extension + PRIVATE + ${DUCKDB_STATIC_EXTRA_LIBS}) + else () + message(WARNING "duckdb static libs are used but the duckdb_generated_extension_loader " + "target was not exported by the DuckDB package - the build may fail to link") + endif () +endif ()