Thread overview
ldc2 -static fails: error: cannot find -lphobos2-ldc or -ldruntime-ldc
Aug 12
Jonathan
Aug 13
kinke
Aug 13
Jonathan
August 12
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.

Any ideas on what needs to happen to solve this issue?
August 13
On Wednesday, 12 August 2020 at 11:34:34 UTC, Jonathan wrote:
> Any ideas on what needs to happen to solve this issue?

Seems like the Gentoo package contains shared druntime/Phobos libs only, no static libs. That's probably what most distros do; some like Alpine have an extra package for the static libs IIRC. The distro packages are community-maintained.

The simplest solution is probably to use an official package from GitHub.
August 13
On Thursday, 13 August 2020 at 07:17:46 UTC, kinke wrote:
> On Wednesday, 12 August 2020 at 11:34:34 UTC, Jonathan wrote:
>> Any ideas on what needs to happen to solve this issue?
>
> Seems like the Gentoo package contains shared druntime/Phobos libs only, no static libs. That's probably what most distros do; some like Alpine have an extra package for the static libs IIRC. The distro packages are community-maintained.
>
> The simplest solution is probably to use an official package from GitHub.

I just found a solution, though it is entirely possible that your suggestion would also work.

Gentoo compiles from source and has use flags.  I didn't see that there was a `static-libs` use flag that was deactivated.  When I activated the flag and recompiled, it works as intended.