Practical Problems with distribution D projects

Adam D. Ruppe destructionator at gmail.com
Wed Feb 26 09:34:44 PST 2014


On Wednesday, 26 February 2014 at 17:08:38 UTC, Assaf Gordon 
wrote:
> In my first message in this thread, I wrote (item #3), that 
> unless I'm missing something, there is no way to build a 
> statically linked binary with D on Linux.

They really aren't far from it out of the box:

$ dmd hellod.d
$ ldd hellod
         linux-gate.so.1 =>  (0xffffe000)
         libpthread.so.0 => /lib/libpthread.so.0 (0xf76db000)
         libm.so.6 => /lib/libm.so.6 (0xf76b5000)
         librt.so.1 => /lib/librt.so.1 (0xf76ac000)
         libc.so.6 => /lib/libc.so.6 (0xf7549000)
         /lib/ld-linux.so.2 (0xf7730000)


It isn't fully static, but those libraries are all pretty basic 
things and generally available on any linux install. The biggest 
problem is probably the libc version not matching on older 
installations.

One option might be to package those .so files right with your 
executable. A poor man's static link.


Anyway, let's try the -static switch we can use to do statically 
linked libc on some programs.

$ dmd hellod.d -c
$ gcc hellod.o -o hellod -m32 
-L/home/me/d/dmd2/linux/bin32/../lib32 -Xlinker --export-dynamic 
-l:libphobos2.a -lpthread -lm -lrt -static

undefined reference to `__tls_get_addr'


BTW if you run "dmd -v yourfile.d" the last line of output is the 
linker command line it runs (via gcc). Then you can copy/paste 
that and tweak the arguments. Here, I added -static.


However, that is *not* a D problem per se, that's a libc 
function. Maybe my system just doesn't have the right stuff 
installed to build a static threaded app.

> I would gladly spend the time to create VMs for each common 
> system setup and package a static binary for it.


If you're doing that, you don't need to do anything special, 
since the vm will link the appropriate libc version anyway, so 
the default build should work.


I betcha if I sent you my binary from my slackware box over to 
your computer it would work even if you are a different distro.


More information about the Digitalmars-d mailing list