Skip to content

Commit

Permalink
Add ability to link libduckdb statically
Browse files Browse the repository at this point in the history
pg_duckdb is not the only Postgres extension using DuckDB these days. If
two extensions both dynamically link to libduckdb.so and install that
library into the Postgres libdir, then it is a race to see which
extension installs their libduckdb last. This can lead to undefined
symbols in any of the DuckDB Postgres extensions.

Signed-off-by: Tristan Partin <[email protected]>
  • Loading branch information
tristan957 committed Feb 21, 2025
1 parent 82d3a0f commit 1c1b391
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@ else
DUCKDB_BUILD_TYPE = release
endif

DUCKDB_LIB = libduckdb$(DLSUFFIX)
DUCKDB_STATIC ?= 0
PG_DUCKDB_LINK_FLAGS = -Wl,-rpath,$(PG_LIB)/ -lpq -Lthird_party/duckdb/build/$(DUCKDB_BUILD_TYPE)/src -L$(PG_LIB) -lstdc++ -llz4
ifeq ($(DUCKDB_STATIC), 1)
DUCKDB_LIB = libduckdb_static.a
PG_DUCKDB_LINK_FLAGS += -l:$(DUCKDB_LIB)
else
DUCKDB_LIB = libduckdb$(DLSUFFIX)
PG_DUCKDB_LINK_FLAGS += -lduckdb
endif

FULL_DUCKDB_LIB = third_party/duckdb/build/$(DUCKDB_BUILD_TYPE)/src/$(DUCKDB_LIB)

ERROR_ON_WARNING ?=
Expand All @@ -54,7 +63,7 @@ override PG_CXXFLAGS += -std=c++17 ${DUCKDB_BUILD_CXX_FLAGS} ${COMPILER_FLAGS} -
# changes to the vendored code in one place.
override PG_CFLAGS += -Wno-declaration-after-statement

SHLIB_LINK += -Wl,-rpath,$(PG_LIB)/ -lpq -Lthird_party/duckdb/build/$(DUCKDB_BUILD_TYPE)/src -L$(PG_LIB) -lduckdb -lstdc++ -llz4
SHLIB_LINK += $(PG_DUCKDB_LINK_FLAGS)

include Makefile.global

Expand Down

0 comments on commit 1c1b391

Please sign in to comment.