LDC 1.42.0
Witold Baryluk
witold.baryluk at gmail.com
Mon Mar 2 02:54:52 UTC 2026
On Monday, 2 March 2026 at 02:16:15 UTC, kinke wrote:
> On Monday, 2 March 2026 at 00:53:45 UTC, Witold Baryluk wrote:
>> Any pointers and instruction on musl usage?
>> […]
>> Without `-static` it compiles, but links to glibc.
>
> This happens when running the Alpine package on a non-musl
> distro. The Alpine compiler targets musl by default, as do its
> bundled druntime and Phobos libraries - incl. 64-bit `real` for
> example (not the 80-bit x87 as for glibc on x86[_64]). For
> linking, it defaults to the `cc` C compiler, assuming that it's
> a matching musl-toolchain one (as on Alpine). On Debian/Ubuntu,
> you can set it via e.g. `-gcc=x86_64-linux-musl-gcc` after
> installing the `musl-dev` apt package. - But it's probably
> best/easiest when using the prebuilt Alpine package in an
> Alpine-based container.
Thanks for the help.
Yeah. I am on Debian.
I tried with `-gcc` flag and it helps, but not quiet
```
user at debian:~/ldc2-1.42.0-alpine-x86_64$ ./bin/ldc2 -static
-gcc=$HOME/musl-1.2.5/./obj/musl-gcc ../hello.d
/usr/bin/x86_64-linux-gnu-ld.bfd:
/usr/lib/gcc/x86_64-linux-gnu/15/libgcc_eh.a(unwind-dw2-fde-dip.o): in function `_Unwind_Find_FDE':
(.text+0x290c): undefined reference to `_dl_find_object'
/usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x2b90): undefined
reference to `_dl_find_object'
collect2: error: ld returned 1 exit status
Error: /home/user/musl-1.2.5/./obj/musl-gcc failed with status: 1
```
And with Debian provided one:
```
user at debian:~/ldc2-1.42.0-alpine-x86_64$ ./bin/ldc2 -static
-gcc=x86_64-linux-musl-gcc ../hello.d
/usr/bin/x86_64-linux-gnu-ld.bfd:
/usr/lib/gcc/x86_64-linux-gnu/15/libgcc_eh.a(unwind-dw2-fde-dip.o): in function `_Unwind_Find_FDE':
(.text+0x290c): undefined reference to `_dl_find_object'
/usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x2b90): undefined
reference to `_dl_find_object'
collect2: error: ld returned 1 exit status
Error: /usr/bin/x86_64-linux-musl-gcc failed with status: 1
```
PS. I do not need curl, it is just first line of failure. I do
understand why phobos complains about static linking to glibc,
i.e. when using NSS for things like hostname resolution, and
stuff - but I do not need NSS, and simplified resolver for musl
is all I need. Same for user / group name resolution.
I did try in `alpine` docker container, with their prepackaged
ldc (I also needed to install clang), and it did produce
musl-linked binary (but it was still I think linked dynamically
to musl)
```
$ podman run --rm -it alpine
/ # apk add ldc clang file
( 1/33) Installing clang21-headers (21.1.2-r2)
...
OK: 733.1 MiB in 49 packages
/ # echo 'import std.stdio; void main(){write("Hello\n");}' >
hello.d
/ # ldc2 -static hello.d
/ # ldd hello
/lib/ld-musl-x86_64.so.1 (0x7fe6f2aeb000)
/ # file hello
hello: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV),
static-pie linked,
BuildID[sha1]=03644e6f92304c90cb0d57585f1c87c1f0d55acd, with
debug_info, not stripped
/ #
```
More information about the Digitalmars-d-announce
mailing list