September 26, 2019
https://issues.dlang.org/show_bug.cgi?id=6952

Alan.W.Irwin1234@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |20244


Referenced Issues:

https://issues.dlang.org/show_bug.cgi?id=20244
[Issue 20244] New dmd option -preview=noXlinker does not work on Linux to build
a simple D application
--
September 26, 2019
https://issues.dlang.org/show_bug.cgi?id=6952

Mike Franklin <slavo5150@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #12 from Mike Franklin <slavo5150@yahoo.com> ---
That behavior is expected.  I've clarified in Issue 20244

--
September 26, 2019
https://issues.dlang.org/show_bug.cgi?id=6952
Issue 6952 depends on issue 20244, which changed state.

Issue 20244 Summary: New dmd option -preview=noXlinker does not work on Linux to build a simple D application https://issues.dlang.org/show_bug.cgi?id=20244

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--
September 26, 2019
https://issues.dlang.org/show_bug.cgi?id=6952
Issue 6952 depends on issue 20244, which changed state.

Issue 20244 Summary: New dmd option -preview=noXlinker does not work on Linux to build a simple D application https://issues.dlang.org/show_bug.cgi?id=20244

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--
September 26, 2019
https://issues.dlang.org/show_bug.cgi?id=6952
Issue 6952 depends on issue 20244, which changed state.

Issue 20244 Summary: New dmd option -preview=noXlinker does not work on Linux to build a simple D application https://issues.dlang.org/show_bug.cgi?id=20244

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--
January 10, 2020
https://issues.dlang.org/show_bug.cgi?id=6952

jens.k.mueller@gmx.de changed:

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

--- Comment #13 from jens.k.mueller@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!

--
May 19, 2022
https://issues.dlang.org/show_bug.cgi?id=6952

Tomoya Tanjo <ttanjo@gmail.com> changed:

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

--- Comment #14 from Tomoya Tanjo <ttanjo@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`.

--
1 2
Next ›   Last »