Page 1 of 1

[RESOLVED] Linux: Very large compiled binary

Posted: Sun Feb 19, 2017 1:53 pm
by Some Moron
I've used Irrlicht before (to some extent) on Windows, but I figured the beginner's board would be the best place for this question since it's probably something very simple. In December I brought about my Year of Linux on Desktop, and decided it was time to get back into game development.

Compiling some samples was no problem, and I was pleased at how smoothly everything went. The issue I have is that the resulting binary is massive. The collision demo compiles at 19.9MB, for instance. I'm pretty sure this is because the libraries are being statically linked rather than dynamic. Is this a good practice or would it be preferable to cut down on the size? If so, how does this long-time Windows developer accomplish it on Linux Mint?

Re: Linux: Very large compiled binary

Posted: Sun Feb 19, 2017 2:29 pm
by CuteAlien
You can get down to ~5m if you remove the debug information (or compile as release which you would do for stuff your release anyway as debug is far slower). You can test by removing debug infos with the 'strip' command.

Dynamic libraries only save you space when you have several apps using the same one. For a single application static linking is usually smaller as the linker can remove everything which is not needed by that application (which it can't do for shared libraries as application might want to use everything). Note that if you want to get your application into a distribution you generally will have to use shared libraries (with the specific version used in that distribution).

If you need to reduce Irrlicht size futher you can also try modifying IrrCompileConfig and remove all options which you don't need (you can also control that by passing corresponding defines from a Makefile which is usually better than modifying the header itself). Note that you have to recompile Irrlicht to do that.

Another reason for large sizes is simply that we generally compile with 64-bit now... if you release it as 32-bit application you could reduce it's size further (but uncommon to do that on Linux, you probably just make it harder for people to run your application).

Also... x MB is nothing these days... so don't worry too much.

Re: Linux: Very large compiled binary

Posted: Sun Feb 19, 2017 4:59 pm
by Some Moron
I didn't think of the whole debug vs. release thing. Stripping symbols and optimizing for speed (O2) cut it below 5mb like you said.

Good to know about the dynamic library space saving. I usually associate "dynamic libraries" with "small executable," but I guess in the long run I'd have to distribute everything together anyway. And I will try to let go of the "smaller is better" idea. It's hard for someone whose role models are Demoscene programmers, but I shall get over it.

Thanks for the help - I can now program in peace.

Re: [RESOLVED] Linux: Very large compiled binary

Posted: Mon Feb 20, 2017 12:56 pm
by hendu
Besides removing the mesh loaders/etc you don't need, compile irr with -ffunction-sections -fdata-sections and then in your app's LDFLAGS add -Wl,-gc-sections. My irr-using binaries are generally under 2mb.

LTO would give even smaller sizes, naturally.