Search code examples
hyperlinkstaticdgentooldc

ldc2 -static fails ld.gold error cannot find -lphobos2-ldc -ldruntime-ldc


tl;dr LDC compiles and links fine until the -static flag is used, then ld.gold cannot find the phobos or druntime libraries.

OS: Gentoo 64-bit Kernel: 5.4.48 DMD version: 2.090 LDC2 version: 1.20.1 (DMD v2.090.1, LLVM 10.0.0)

I'm attempting to statically link some files that I made so that the binaries can be run without requiring phobos. If I try to compile with either dmd or ldc2, everything works properly, however when I compile with:

$ ldc2 -static -main filename

I get the following error:

/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.gold: error: cannot find -lphobos2-ldc
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.gold: error: cannot find -ldruntime-ldc```

Along with many error: undefined reference to 'XYZ' that I believed are caused by the lack of phobos and druntime libraries being found.

I have tried running cc on its own specifying where my libphobos2-ldc-shared.so and libdruntime-ldc-shared.so files are, while specifying these files, with the same results:

$ /usr/bin/cc scans.o -static -o scans -fuse-ld=gold -L/usr/lib/ldc2/1.20/lib64 -libphobos2-ldc-shared.so -libdruntime-ldc-shared.so -Wl,--gc-sections -lrt -ldl -lpthread -lm -m64 -v

/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.gold: error: cannot find -libphobos2-ldc-shared.so
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld.gold: error: cannot find -libdruntime-ldc-shared.so

I have also tried updating LD_LIBRARY_PATHS in my ~/.bashrc (and sourcing it after the change), but this had no effect.

I can't seem to find anyone else who has had this or a similar issue, but I feel like it may have something to do with how gentoo deals with the different D compilers.

I have tried using both the eselect and layman directions, removing ldc2 to follow the directions for each method, with no effect. Something worrying is that the executable and library paths mentioned in the wiki (https://wiki.gentoo.org/wiki/Dlang#Executables_paths) do not exist on my system. I also couldn't find any ldc2 config files, nor did adding and editing ~/.ldc2 or ~/.config/ldc2 change anything.

I have now also tried removing dub, dmd, ldc2, and layman, and reinstalling (layman first, adding the overlay, then installing dmd and ldc2), but I get the same problem, and the paths and configuration files still aren't in the place that the gentoo wiki on dlang says they should be.

Any ideas on what needs to happen to solve this issue?


Solution

  • In gentoo, there is a use flag static-libs that I didn't see. I recompiled with this flag active and it works properly.