Static freeimage library produces huge binary
-
- Gnoblar
- Posts: 22
- Joined: Mon Nov 24, 2014 8:02 pm
Static freeimage library produces huge binary
Hi all,
I am compiling ogre from source using visual studio 2013. One of the dependencies I want to use is free image. I build it as a static library (I don't want to use DLL) and also set code generation to multi threaded only so I statically link against the run time libraries (like I've done all my 3rd Party libraries) and compiled. The end result is a freeimage.lib file of 85.5mb and a debug version of 55.5mb. Surely this can't be right. Anyone else experience anything similar and is there anything I can do about it? Thanks
I am compiling ogre from source using visual studio 2013. One of the dependencies I want to use is free image. I build it as a static library (I don't want to use DLL) and also set code generation to multi threaded only so I statically link against the run time libraries (like I've done all my 3rd Party libraries) and compiled. The end result is a freeimage.lib file of 85.5mb and a debug version of 55.5mb. Surely this can't be right. Anyone else experience anything similar and is there anything I can do about it? Thanks
- HackerManiac
- Halfling
- Posts: 50
- Joined: Thu Oct 30, 2014 9:46 am
- x 3
Re: Static freeimage library produces huge binary
Myself, for debug builds I end up with FreeImage being 63,2 mb and I'm afraid this is normal. Remember that FreeImage is a collection of many other libs (libPNG, libTIFF4, etc.) so its size is quite a normal thing.
Edit: I downloaded the pre-built SDK from http://www.ogre3d.org/forums/viewtopic.php?f=4&t=69274, and there the debug version of FreeImage amounts to 99,2mb.
Edit: I downloaded the pre-built SDK from http://www.ogre3d.org/forums/viewtopic.php?f=4&t=69274, and there the debug version of FreeImage amounts to 99,2mb.
-
- Gnoblar
- Posts: 22
- Joined: Mon Nov 24, 2014 8:02 pm
Re: Static freeimage library produces huge binary
Wow ok thanks. Is it possible for me to remove some of the libraries that freeimage has included that I don't want without upsetting ogre? I only really want PNG and DDS support. Thanks!
- HackerManiac
- Halfling
- Posts: 50
- Joined: Thu Oct 30, 2014 9:46 am
- x 3
Re: Static freeimage library produces huge binary
I haven't done this myself, but if you use a pre-built SDK, like from here http://www.ogre3d.org/forums/viewtopic.php?f=4&t=69274 , it provides all those libs built separately in the ogredeps package. I think if you linked against them and not FreeImage it should work, no guarantee, though. Good luck
- Kojack
- OGRE Moderator
- Posts: 7157
- Joined: Sun Jan 25, 2004 7:35 am
- Location: Brisbane, Australia
- x 534
Re: Static freeimage library produces huge binary
Remember that not all of a static library is added to an executable when linked, only the parts you use are. Having a large static library is only a problem if you are giving out a source build, it doesn't affect the final exe.
-
- Minaton
- Posts: 933
- Joined: Mon Mar 05, 2012 11:37 am
- Location: Germany
- x 110
Re: Static freeimage library produces huge binary
I'm building FreeImage with all sub libraries, the linker should remove the not used stuff as Kojack said. Also, don't compare the debug version with the release version.
- syedhs
- Silver Sponsor
- Posts: 2703
- Joined: Mon Aug 29, 2005 3:24 pm
- Location: Kuala Lumpur, Malaysia
- x 51
Re: Static freeimage library produces huge binary
The linker will not remove code which resembles something like this:-
Because there is no dead-code elimination - the fact that the exe only use Png is only known during runtime.
And if I am not mistaken, FreeImage is similar to this - so you have to remove manually the unneeded file type code.
Code: Select all
if it is png then doPngOpen
else if it is bmp then doBmpOpen
And if I am not mistaken, FreeImage is similar to this - so you have to remove manually the unneeded file type code.
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Static freeimage library produces huge binary
It's true ... the linker only knows which symbols you need to generate a working executable at link time. So you are gonna include everything Ogre uses, which is still probably a lot less than everything in freeimage. Judge the binary size by the final binary, not the intermediary static libraries.
But if binary size is a big issue, it shouldn't be hard to strip down to just what you need. IIRC Ogre has its own dds codec implementation, and there is a png lib that doesn't use freeimage (I remember seeing them on the forums).
But if binary size is a big issue, it shouldn't be hard to strip down to just what you need. IIRC Ogre has its own dds codec implementation, and there is a png lib that doesn't use freeimage (I remember seeing them on the forums).
- syedhs
- Silver Sponsor
- Posts: 2703
- Joined: Mon Aug 29, 2005 3:24 pm
- Location: Kuala Lumpur, Malaysia
- x 51
Re: Static freeimage library produces huge binary
Fortunately, for FreeImage case - it is easy to remove which file format is not needed. You just need to edit probably one source and the project file (cant remember the exact modifications needed). If you only a jpeg/png and nothing else, you can get more than 1MB file size reduction (I have tested it).
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
-
- Minaton
- Posts: 933
- Joined: Mon Mar 05, 2012 11:37 am
- Location: Germany
- x 110
Re: Static freeimage library produces huge binary
FreeImage is using libpng. There are internal plugins for every useable filetype, you can delete them and remove them from the factory.c6burns wrote:IIRC Ogre has its own dds codec implementation, and there is a png lib that doesn't use freeimage (I remember seeing them on the forums).
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Static freeimage library produces huge binary
Totally, I just know someone didn't want to use freeimage and made a standalone png codec. If I remember correctly, they didn't think freeimage had a compatible license (but it actually did)Transporter wrote:FreeImage is using libpng. There are internal plugins for every useable filetype, you can delete them and remove them from the factory.c6burns wrote:IIRC Ogre has its own dds codec implementation, and there is a png lib that doesn't use freeimage (I remember seeing them on the forums).
But yeah agreed it's prob easier to just strip down whats there
-
- Minaton
- Posts: 933
- Joined: Mon Mar 05, 2012 11:37 am
- Location: Germany
- x 110
Re: Static freeimage library produces huge binary
FreeImage/Static
- Visual Studio 2010
- x86
- Debug: 54.9 MB
- Release: 22.4 MB
- amd64
- Debug: 72.7 MB
- Release: 31.7 MB
- x86
- Visual Studio 2012
- x86
- Debug: 71.4 MB
- Release: 30.4 MB
- x64
- Debug: 97.3 MB
- Release: 41.0 MB
- x86
- Visual Studio 2013
- x86
- Debug: 64.3 MB
- Release: 25.7 MB
- x64
- Debug: 88.3 MB
- Release: 36.2 MB
- x86