Small program producing binary with large filesize
Prokop Hapala
prokophapala at gmail.com
Mon Oct 21 19:20:04 UTC 2019
On Wednesday, 1 August 2018 at 15:58:53 UTC, Jacob Shtokolov
wrote:
> On Tuesday, 31 July 2018 at 15:19:19 UTC, Dan Barbarito wrote:
>> Hi all,
>>
>> I am starting to write a command line tool.
>
> Hi!
>
> First, Vibe.d will increase your binary size because it
> contains a lot of unnecessary things inside it. So instead of
> using the entire vibe.d library, you may point dub to specific
> vibe.d parts, like `vibe.d:core`, `vibe.d:http` etc.
>
> If you put the whole vibe.d framework as a dub dependency and
> use it like `import vibe;` the things like mongodb drivers,
> email libraries, redis driver etc. will be linked to your
> binary as well, even if you don't need them.
>
> Second, you need to compile your code in the release mode to
> cut all debug information out of it. Also, you can try to use
> the `strip` command line tool to cut all export symbols if your
> binary is an executable file, not a library. This will reduce
> the size. In some cases a lot.
>
> The third thing is already mentioned: by default, the DMD
> compiler builds and links the code statically. In other words,
> your binary contains parts of the DRuntime and the Phobos
> libraries (those parts that you've used in your program).
>
> This thing helps to distribute compiled binaries without
> external dependencies (except libc and libpthread), because
> your binary is already contains all needed stuff.
>
> If you're not happy with it, you can try to use the LDC
> compiler, which uses the dynamic linking by default. Your
> binary will be really tiny, but in order to execute it, you'll
> need to have the libdruntime.so and libphobos.so installed in
> your system. This may add additional issues if you plan to
> distribute your program.
>
> Sadly, we still don't have the D runtime libraries installed in
> all popular OSes. Currently only the libc has this privilege 😀
>
> I hope the situation will change in the future.
Hi, I was trying with ldc (source ~/dlang/ldc-1.17.0/activate)
and the size of binary is even worse
dub with dmd 2.89 MB
dub with ldc 3.50 MB
It is very simple program but use derelict-gl3 and derelict-sdl2
I want to link them all dynamically (I don't plan to distribute
binary any time soon)
What exactly should I specify to make it link dynamcially and
produce as small binary as possible (without increasing
compilation time) ?
More information about the Digitalmars-d-learn
mailing list