[RESOLVED] Linux: Very large compiled binary

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Some Moron
Posts: 12
Joined: Sat Jun 04, 2011 7:04 pm

[RESOLVED] Linux: Very large compiled binary

Post 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?
Last edited by Some Moron on Sun Feb 19, 2017 4:59 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Linux: Very large compiled binary

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Some Moron
Posts: 12
Joined: Sat Jun 04, 2011 7:04 pm

Re: Linux: Very large compiled binary

Post 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.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: [RESOLVED] Linux: Very large compiled binary

Post 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.
Post Reply