duckdb / duckdb/pg_duckdb

Build fails on GCC 8 due to missing -lstdc++fs when using std::filesystem

Open
#848 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
3.2k
Forks
204
PR merge metrics
No merged PRs in 30d

Description

### What happens?

When building pg_duckdb on systems using GCC 8 (e.g. CentOS 8), the PostgreSQL extension fails to load due to unresolved std::filesystem symbols.

GCC 8 supports std::filesystem but requires explicitly linking against libstdc++fs. This is no longer necessary in GCC 9+, where filesystem was merged into the standard C++ library.

### To Reproduce

On a system with GCC 8.x (e.g., CentOS 8):

Build pg_duckdb using the current Makefile

Load the extension in PostgreSQL:

sql
```
LOAD 'pg_duckdb';
```
You will encounter an error like:
```
undefined symbol: _ZNSt10filesystem7__cxx114path14_M_split_cmptsEv
```

Diagnosis:

Inspecting pg_duckdb.so with nm -D shows unresolved symbols related to std::filesystem:
```
nm -D pg_duckdb.so | grep filesystem
```
```
# Output:
# U _ZNSt10filesystem7__cxx114path14_M_split_cmptsEv
# U _ZNSt10filesystem18create_directoriesERKNS_7__cxx114pathE
```

These symbols are undefined unless -lstdc++fs is explicitly passed during linking on GCC 8.

Suggested Fix:

Modify the Makefile to detect if GCC version is 8 and add -lstdc++fs accordingly:

```
GCC_VERSION_MAJOR := $(shell g++ -dumpversion | cut -f1 -d.)
ifeq ($(shell [ $(GCC_VERSION_MAJOR) -eq 8 ] && echo true),true)
PG_DUCKDB_LINK_FLAGS += -lstdc++fs
endif
```
This keeps the build compatible across all compiler versions:

GCC < 8: no change (but std::filesystem isn't usable anyway)

GCC 8: adds required -lstdc++fs

GCC ≥ 9: safely ignored

Let me know what you think!
Thanks for all the amazing work on pg_duckdb! 🙌

### OS:

linux centos8 x86

### pg_duckdb Version (if built from source use commit hash):

12dee2e43520144059f007d37ce4863b9c879d31

### Postgres Version (if built from source use commit hash):

16.9

### Hardware:

_No response_

### Full Name:

liu chuang

### Affiliation:

liuchuang66888@gmail.com

### What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a source build

### Did you include all relevant data sets for reproducing the issue?

Yes

### Did you include all code required to reproduce the issue?

- [x] Yes, I have

### Did you include all relevant configuration (e.g., CPU architecture, Linux distribution) to reproduce the issue?

- [x] Yes, I have

Contributor guide

Open the contributing guide

Research direction

Start by inspecting the Makefile and the existing PostgreSQL extension link flags. Reproduce the GCC 8 build on CentOS 8, then load pg_duckdb in PostgreSQL and inspect pg_duckdb.so with nm -D | grep filesystem. Done means the extension loads successfully and the unresolved std::filesystem symbols no longer appear.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.