[Issue 6952] Static Linking on Linux

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 19 07:25:56 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=6952

Tomoya Tanjo <ttanjo at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ttanjo at gmail.com

--- Comment #14 from Tomoya Tanjo <ttanjo at gmail.com> ---
I have the same issue on Alpine Linux (dmd installed via apk, and dmd 7f88bab).

`dmd -v` shows the following link command:

```
cc sample.o -o sample -m64 -Xlinker --export-dynamic
-L./generated/linux/release/64/../../../../../phobos/generated/linux/release/64
-Xlinker -Bstatic -lphobos2 -Xlinker -Bdynamic -lpthread -lm -lrt -ldl
```

To make a static binary, we have to:
- add `-static` option, and
- remove `-Xlinker -Bdynamic` from the command line or add extra `-Xlinker
-Bstatic` to cancel dynamic link options.

dmd provides ways to solve the former case: `-Xcc` and `-L`.

On the other hand, there are no ways to solve the latter case.
It makes harder to build a static binary with dub.

It would be nice if dmd provides a way to solve the latter case to cancel
`-Xlinker -Bdynamic`.

--


More information about the Digitalmars-d-bugs mailing list