How to build a statically linked executable, before i loose my mind

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Sat Jul 13 15:46:52 UTC 2024


On 14/07/2024 2:53 AM, ryuukk_ wrote:
> First of all, i build with `ldmd2`
> 
> Second of all, i do not use DUB
> 
> Lastly, it fails with:
> 
> 
> ```
> ldmd2 -L-static  ...
> ```
> 
> ```
> /usr/bin/ld: cannot find -lphobos2-ldc-shared: No such file or directory
> /usr/bin/ld: cannot find -ldruntime-ldc-shared: No such file or directory
> ```
> 
> 
> Why does it complain about SHARED when passing STATIC?

Doesn't look like the switch does what you are thinking it does.

```
-static
On systems that support dynamic linking, this overrides -pie and 
prevents linking with the shared libraries. On other systems, this 
option has no effect.
```

https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

Preventing linking against, and swapping two different binaries to link 
against are different things.

Specifying to link against the shared libraries for druntime + phobos is 
done by the compiler, not the linker.

You might want to try ``--link-defaultlib-shared=false`` instead.


More information about the Digitalmars-d-learn mailing list