Thread overview
[Issue 6952] New: Static Linking on Linux
Nov 15, 2011
David Simcha
Nov 15, 2011
Jonathan M Davis
November 15, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6952

           Summary: Static Linking on Linux
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: dsimcha@yahoo.com


--- Comment #0 from David Simcha <dsimcha@yahoo.com> 2011-11-15 09:08:02 PST ---
It seems that the stuff that DMD outputs to GCC on Linux is misconfigured for static linking.  I've observed this on several machines with various Linux distros, all of which can statically link a C hello world program successfully with the machine's GCC install.

hello.d:

import std.stdio;

void main() {
    write("Hello, world\n");
}

$ dmd -L-static hello.d
/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status
--- errorlevel 1

Yet somehow when I compile/link a C hello world on the same machine it Just Works:

hello.c:

#include <stdio.h>

int main() {
    printf("Hello, world.\n");
    return 0;
}

$ gcc -o hello -static hello.c
$ ./hello
Hello, world.
$ file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically
linked, for GNU/Linux 2.6.15, not stripped

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 15, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6952


Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com
         OS/Version|Windows                     |Linux


--- Comment #1 from Steven Schveighoffer <schveiguy@yahoo.com> 2011-11-15 09:40:22 PST ---
The issue is that -Lxxx passes the parameter like this:

-Xlinker xxx

Which means to gcc "pass this argument to the linker"

Whereas your gcc compile line is passing -static to the compiler.

doing this:

gcc -Xlinker -static -o hello hello.c

should result in the same failure (not tested).

It's not that dmd outputs misconfigured code, it's just that the link line is not geared towards static linking.  I'm not sure you want to do static linking anyways.  It's not supported by GCC IIRC.

You can fix this by doing dmd -v, then running the link line, removing the -Xlinker arg in front of -static.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 15, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6952


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com


--- Comment #2 from Jonathan M Davis <jmdavisProg@gmx.com> 2011-11-15 11:17:07 PST ---
See Bug# 4376.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 16, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6952



--- Comment #3 from Steven Schveighoffer <schveiguy@yahoo.com> 2011-11-16 05:26:34 PST ---
*** Issue 4376 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------