www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Phobos still being statically linked in?

reply Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
I went back to see my first post here in the D world two years ago:

http://forum.dlang.org/post/mailman.413.1369930723.13711.digitalmars-d-learn puremagic.com

I had noted then with surprise that the most basic Hello World program took 
300K+ with rdmd, but now it seems it's much more i.e. 600K+ with dmd (since 
rdmd doesn't seem to leave out any executables any more). ldc2 is much 
better at 300K+ but still doesn't compare to C/C++...

$ cat namaste.d 
import std.stdio;
void main () { writeln("Namaste!"); }
$ dmd namaste.d && ls -l namaste*
-rwxrwxr-x 1 samjnaa samjnaa 645544 Oct 17 15:21 namaste
-rw-rw-r-- 1 samjnaa samjnaa     56 Oct 17 15:20 namaste.d
-rw-r--r-- 1 samjnaa samjnaa  14932 Oct 17 15:21 namaste.o
$ ldc2 namaste.d && ls -l namaste*
-rwxrwxr-x 1 samjnaa samjnaa 346144 Oct 17 15:21 namaste
-rw-rw-r-- 1 samjnaa samjnaa     56 Oct 17 15:20 namaste.d
-rw-rw-r-- 1 samjnaa samjnaa  25456 Oct 17 15:21 namaste.o
$ dmd --version
DMD64 D Compiler v2.068.2
Copyright (c) 1999-2015 by Digital Mars written by Walter Bright
$ ldc2 -version
LDC - the LLVM D compiler (0.16.0-beta2):
  based on DMD v2.067.1 and LLVM 3.7.0
  Default target: x86_64-unknown-linux-gnu
  Host CPU: haswell

I was told then 
(http://forum.dlang.org/post/op.wxwn0jys54xghj puck.auriga.bhead.co.uk) that 
the reason was that the library was linked in statically.

Is this still true as it seems to be? If so, how do I tell dmd/ldc2 not to 
do that, but to use the available SO at:

/usr/lib/x86_64-linux-gnu/libphobos2.so.0.68.2

-- 

Oct 17 2015
next sibling parent reply Marc =?UTF-8?B?U2Now7x0eg==?= <schuetzm gmx.net> writes:
Yes, it's still linked statically by default, at least with DMD. 
I don't know why this wasn't changed yet, I just tried linking 
against libphobos.so and it worked. The resulting binary is then 
down to 13 Kb, after stripping.

On the topic of executable size, Vladimir Panteleev did some work 
to check it automatically for each version of DMD:

http://blog.thecybershadow.net/2015/05/05/is-d-slim-yet/
http://digger.k3.1azy.net/trend/
Oct 17 2015
next sibling parent reply Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
Marc Schütz wrote:

 Yes, it's still linked statically by default, at least with DMD.
 I don't know why this wasn't changed yet, I just tried linking
 against libphobos.so and it worked. The resulting binary is then
 down to 13 Kb, after stripping.
Wow that's nice to hear! Can you outline the steps to link any given .d file against libphobos.so? Thanks! --
Oct 17 2015
parent Marc =?UTF-8?B?U2Now7x0eg==?= <schuetzm gmx.net> writes:
On Saturday, 17 October 2015 at 13:54:12 UTC, Shriramana Sharma 
wrote:
 Marc Schütz wrote:

 Yes, it's still linked statically by default, at least with 
 DMD. I don't know why this wasn't changed yet, I just tried 
 linking against libphobos.so and it worked. The resulting 
 binary is then down to 13 Kb, after stripping.
Wow that's nice to hear! Can you outline the steps to link any given .d file against libphobos.so?
Unfortunately, I haven't found a switch that makes DMD use dynamic linking. Maybe I just missed it... So, you have to do it step by step: 1) Use the `-c` switch to make the compiler output: dmd -O -inline -c foo.d This generates `foo.o`. 2) Link by calling `gcc`: gcc -o foo foo.o -lphobos2 This calls `ld` with the right options and results in a binary `foo`. 3) Optionally, strip the binary to make it smaller: strip foo
Oct 17 2015
prev sibling next sibling parent Shriramana Sharma <samjnaa_dont_spam_me gmail.com> writes:
Marc Schütz wrote:

 Yes, it's still linked statically by default, at least with DMD.
 I don't know why this wasn't changed yet, I just tried linking
 against libphobos.so and it worked. The resulting binary is then
 down to 13 Kb, after stripping.
Filed https://issues.dlang.org/show_bug.cgi?id=15218 --
Oct 17 2015
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2015-10-17 13:28, Marc Schütz wrote:
 Yes, it's still linked statically by default, at least with DMD. I don't
 know why this wasn't changed yet
1. It makes it easier to distribute binaries since most computers won't have a Phobos and druntime installed 2. There's no guaranteed ABI compatibly between different release of D -- /Jacob Carlborg
Oct 18 2015
parent Dominikus Dittes Scherkl <Dominikus.Scherkl continental-corporation.com> writes:
On Sunday, 18 October 2015 at 16:02:50 UTC, Jacob Carlborg wrote:
 On 2015-10-17 13:28, Marc Schütz wrote:
 Yes, it's still linked statically by default, at least with 
 DMD. I don't
 know why this wasn't changed yet
1. It makes it easier to distribute binaries since most computers won't have a Phobos and druntime installed
It's not too complicated to deliver those two files in addition to the executable
 2. There's no guaranteed ABI compatibly between different 
 release of D
That it the really bad part - if I were to ship the librarys only once, I would prefer it. But pretty much every time? NO.
Oct 20 2015
prev sibling next sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 17 October 2015 at 10:00:20 UTC, Shriramana Sharma 
wrote:
 Is this still true as it seems to be? If so, how do I tell 
 dmd/ldc2 not to do that, but to use the available SO at:
I'm not sure about ldc but the dmd option `-defaultlib=libphobos2.so` should do it. I think ldmd also works with that.
Oct 17 2015
prev sibling parent reply Marco Leise <Marco.Leise gmx.de> writes:
For the Gentoo Linux DMD package I made dynamic linking the
default. It's not just Phobos but other libraries as well,
like GtkD and what else you link into your executable.

A simple GUI converting text in the clipboard on button press
is at around 553 KiB now. With static linking it is 6 MiB.

-- 
Marco
Oct 18 2015
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 10/18/2015 01:37 PM, Marco Leise wrote:
 For the Gentoo Linux DMD package I made dynamic linking the
 default. It's not just Phobos but other libraries as well,
 like GtkD and what else you link into your executable.

 A simple GUI converting text in the clipboard on button press
 is at around 553 KiB now. With static linking it is 6 MiB.
How large is Hello, word when dynamically linked? -- Andrei
Oct 19 2015
next sibling parent deadalnix <deadalnix gmail.com> writes:
On Monday, 19 October 2015 at 16:07:02 UTC, Andrei Alexandrescu 
wrote:
 On 10/18/2015 01:37 PM, Marco Leise wrote:
 For the Gentoo Linux DMD package I made dynamic linking the
 default. It's not just Phobos but other libraries as well,
 like GtkD and what else you link into your executable.

 A simple GUI converting text in the clipboard on button press
 is at around 553 KiB now. With static linking it is 6 MiB.
How large is Hello, word when dynamically linked? -- Andrei
And how much of it is pulled in via Object.factory ? I'd bet a lot.
Oct 19 2015
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2015-10-19 18:07, Andrei Alexandrescu wrote:

 How large is Hello, word when dynamically linked? -- Andrei
When I did that back in the days with D1 and Tango it was 16KB. Same as a C Hello World. -- /Jacob Carlborg
Oct 19 2015