2

I found a simple Hello World program D executable is big size, about 9.2 MiB. I'm using gdc-4.8 compiler. Is this a feature or some kind of bug?

Thanks for all responses!

  • http://stackoverflow.com/a/2649430/2026276 – Bauss Jul 12 '15 at 09:26
  • 3
    run `strip yourprogram` and it should trim, it way down. gcd does lots of debug info – Adam D. Ruppe Jul 12 '15 at 18:43
  • strip does really work. From 10.3 MB to 1.8 MB (I'm actually pretty happy with that size). I think you should post your comment as an answer to this question. If there is no better answer than this, I will absolutely take this as a solution. Thanks – user5555332 Jul 13 '15 at 06:51

1 Answers1

3

I guess you are statically linking against the debug versions of the standard libraries.

First, the size of the executable depends on the use of dynamic vs. static linking of the standard libraries. If you statically link your executable then debug information is another contributor to size.

In numbers (I don't have gdc at hand):

  • compiled with ldc2, statically linked: 315KiB
  • compiled with ldc2 with debug info, statically linked: 2.9MiB
  • compiled with dmd, dynamically linked: 51KiB
  • compiled with dmd with debug info, statically linked: 77KiB

As far as I know gdc does not use/support -gc-section which also contributes to executable size.

Kai Nacke
  • 336
  • 1
  • 6
  • How should I dynamically linked with it? I'm a beginner to D. Sorry for asking more. Thanks. – user5555332 Jul 13 '15 at 07:02
  • @interprog, so how do you dynamically link? :) Thanks! – Andre Polykanine Jul 16 '15 at 11:05
  • @MenelionElensúlë I'm actually don't find the exact way of doing that, and I don't even know if what I'm doing is the right way to dynamically linking. Actually, I found the way to dynamically linking with C - http://dlang.org/dll-linux.html – user5555332 Jul 18 '15 at 05:48
  • @MenelionElensúlë Anyway, if you know how to linking it the right way, feel free to post in the comments. I gonna appreciate it very much. Thanks! :) – user5555332 Jul 18 '15 at 05:54
  • yes, I would also like to link dynamically. With `dub run --compiler=dmd --build=release -defaultlib=libphobos2.so` I still get 1 MB binary (use Derelict-gl3 and Derelict-sdl2 ) ... so I would like to get at least to these 51Kb (resp. 77 Kb) mentioned in the above post – Prokop Hapala Oct 22 '19 at 10:12