digitalmars.D - Phobos still being statically linked in?
- Shriramana Sharma (33/33) Oct 17 2015 I went back to see my first post here in the D world two years ago:
- Marc =?UTF-8?B?U2Now7x0eg==?= (8/8) Oct 17 2015 Yes, it's still linked statically by default, at least with DMD.
- Shriramana Sharma (6/10) Oct 17 2015 Wow that's nice to hear! Can you outline the steps to link any given .d ...
- Marc =?UTF-8?B?U2Now7x0eg==?= (14/21) Oct 17 2015 Unfortunately, I haven't found a switch that makes DMD use
- Shriramana Sharma (4/8) Oct 17 2015 Filed https://issues.dlang.org/show_bug.cgi?id=15218
- Jacob Carlborg (6/8) Oct 18 2015 1. It makes it easier to distribute binaries since most computers won't
- Dominikus Dittes Scherkl (5/13) Oct 20 2015 It's not too complicated to deliver those two files in addition
- Adam D. Ruppe (5/7) Oct 17 2015 I'm not sure about ldc but the dmd option
- Marco Leise (7/7) Oct 18 2015 For the Gentoo Linux DMD package I made dynamic linking the
- Andrei Alexandrescu (2/7) Oct 19 2015 How large is Hello, word when dynamically linked? -- Andrei
- deadalnix (4/12) Oct 19 2015 And how much of it is pulled in via Object.factory ? I'd bet a
- Jacob Carlborg (5/6) Oct 19 2015 When I did that back in the days with D1 and Tango it was 16KB. Same as
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
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
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
On Saturday, 17 October 2015 at 13:54:12 UTC, Shriramana Sharma wrote:Marc Schütz wrote: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 fooYes, 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?
Oct 17 2015
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
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 yet1. 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
On Sunday, 18 October 2015 at 16:02:50 UTC, Jacob Carlborg wrote:On 2015-10-17 13:28, Marc Schütz wrote:It's not too complicated to deliver those two files in addition to the executableYes, it's still linked statically by default, at least with DMD. I don't know why this wasn't changed yet1. It makes it easier to distribute binaries since most computers won't have a Phobos and druntime installed2. There's no guaranteed ABI compatibly between different release of DThat 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
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
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
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
On Monday, 19 October 2015 at 16:07:02 UTC, Andrei Alexandrescu wrote:On 10/18/2015 01:37 PM, Marco Leise wrote:And how much of it is pulled in via Object.factory ? I'd bet a lot.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
On 2015-10-19 18:07, Andrei Alexandrescu wrote:How large is Hello, word when dynamically linked? -- AndreiWhen 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