Bug 4376 – Cannot build static binaries; running dmd with flag -L-static fails to compile
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2010-06-23T11:35:00Z
Last change time
2014-02-15T02:44:15Z
Assigned to
nobody
Creator
issues.dlang
Comments
Comment #0 by issues.dlang — 2010-06-23T11:35:33Z
I would like to be able to generate binaries that don't depend on any external libraries whatsoever. In linux at least, when dmd creates a program normally, the resulting binary depends on various system libraries. For instance, hello world ends up with these dependencies per ldd:
linux-gate.so.1 => (0xb783b000)
libpthread.so.0 => /lib/libpthread.so.0 (0xb77fd000)
libm.so.6 => /lib/libm.so.6 (0xb77d8000)
libc.so.6 => /lib/libc.so.6 (0xb768c000)
/lib/ld-linux.so.2 (0xb783c00
Want I want, is for ldd to say
not a dynamic executable
The way to get this happen normally is to give gcc the linker flag -static. If I compile object files with dmd and then link with gcc using -static, then I can get a static binary. However, if I try and both build and link with dmd, it fails. If I run
dmd prog.d -L-static
(which as I understand it, is passes the -static flag on to gcc for the linking phase), I get the error
/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status
--- errorlevel 1
Why having dmd use gcc to do the linking instead of my doing it directly fails to work, I don't know, but it's rather annoying. I shouldn't have to do the linking myself to get a static binary.
Comment #1 by schveiguy — 2011-11-16T05:26:34Z
Marking as duplicate of later bug, because there is more information there.
*** This issue has been marked as a duplicate of issue 6952 ***