[Issue 6952] Static Linking on Linux

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 10 23:09:39 UTC 2020


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

jens.k.mueller at gmx.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jens.k.mueller at gmx.de

--- Comment #13 from jens.k.mueller at gmx.de ---
I tried building a statically executable on Linux recently. When reading this
issue it sounds as if the problem was solved. But I cannot make David's example
work.

$ cat hello.d
void main()
{
    import std.stdio;
    writeln("Hello, World!");
}

$ dmd --version
DMD64 D Compiler v2.089.1

Note that the introduced -preview=noXlinker was replaced by -Xcc (see
https://github.com/dlang/dmd/commit/f0bd9351a704edf8531838b2a49041ac9244668a#diff-6b306396aa9fdbc560492611d41dd56f
and
https://github.com/dlang/dmd/commit/c45c17327868cc376fe8fad9f48bdd28d687b45f#diff-6b306396aa9fdbc560492611d41dd56f).

But

$ dmd -Xcc=-static hello.d

doesn't create a statically linked executable.

$ ldd hello
        linux-vdso.so.1 (0x00007fff9cd94000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
(0x00007fdce0d5f000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fdce0bdc000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fdce0bd2000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fdce0bcd000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fdce0a0c000)
        /lib/ld64.so.1 => /lib64/ld-linux-x86-64.so.2 (0x00007fdce0d87000)

which you can verify when adding -v which reports

cc hello.o -o hello -m64 -static -Xlinker --export-dynamic
-L/home/jkm/dlang/dmd-2.089.1/linux/bin64/../lib64 -Xlinker -Bstatic -lphobos2
-Xlinker -Bdynamic -lpthread -lm -lrt -ldl

At the end of the line you can see that there are still dynamically linked
libraries. It is true that linking doesn't fail but still the compiler doesn't
generate what it was asked for. That's why I think this issue it not solved.
But maybe I'm doing it wrong. If so let me know how to create a statically
linked executable using dmd. As a workaround for now I would even consider
using the C compiler okay. But I couldn't even make this work.

By the way with ldc it works (tested with version 1.19.0).

$ ldc2 -static hello.d
$ ldd hello
        not a dynamic executable
$ ./hello
Hello, World!

--


More information about the Digitalmars-d-bugs mailing list