Skip to content

Fix bug with passing shared libraries to ldc2 (D/dlang) - #16170

Open
exhu wants to merge 5 commits into
mesonbuild:masterfrom
exhu:fix-ldc2-so-link
Open

Fix bug with passing shared libraries to ldc2 (D/dlang)#16170
exhu wants to merge 5 commits into
mesonbuild:masterfrom
exhu:fix-ldc2-so-link

Conversation

@exhu

@exhu exhu commented Aug 29, 2026

Copy link
Copy Markdown

LLM usage disclosure: i've consulted google's gemini to find out the place where and how to write a unit test here since I don't write python these days.

Current meson produces invalid command to build Dlang app that depends on an internal static C library built with meson that depends on a system shared library.

I've added a minimal test case to demonstrate, but it depends on blkid library and pkg-config (i've tried other libraries like zlib but it's unreliable, looks like ldc2 sorts the inputs, and there's no such problem with shared libraries built as a subproject). Overall I'm not sure if it's acceptable to put a test into this directory because it depends on a library to be installed.

This is the error before fix:

meson setup _build .

18 so dependency via clib (fix-ldc2-so-link)> ninja -C _build
ninja: Entering directory `_build'
[4/4] Linking target prog
FAILED: prog 
ldc2  -of=prog prog.p/main.d.o -L=--allow-shlib-undefined -link-defaultlib-shared -L=clib/libclib.a /usr/lib/x86_64-linux-gnu/libblkid.so
/usr/bin/ld: clib/libclib.a.p/clib.c.o: in function `clib_call_blkid':
/home/yur/projects/meson/test cases/d/18 so dependency via clib/_build/../clib/clib.c:5:(.text+0xe): undefined reference to `blkid_init_debug'
collect2: error: ld returned 1 exit status
Error: /usr/bin/cc failed with status: 1
ninja: build stopped: subcommand failed.

The fix is that "/usr/lib/x86_64-linux-gnu/libblkid.so" must be prefixed with "-L=" so that ldc2 passes it to the linker after the static library that references libblkid, otherwise it's passed before and thus unresolved reference.

@exhu
exhu requested review from dcbaker and jpakkane as code owners August 29, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants