tags:

views:

203

answers:

7

I have a static library project with standard debug/release build options. I was intrigued to spot that while the debug .lib is a fairly large 22Mb, the release one is a whopping 100Mb. And this is not a massive code-base either, about 75 classes and none of them very giant.

My questions are whether this is normal, and whether I should care?

A: 

Ideally release lib should be smaller than debug one.

I guess you may be statically linking other libs such as MFC ,ATL etc...

check you release and debug build setting.

use #pragma once to avoid multiple time file inclusion.

Ashish
A: 

I would typically expect the reverse...

Is it possible that there are big swaths of code inside preprocessor included blocks that only get included in release builds?

Template code is especially suspect in this case.

Update

I think that the issue is most likely caused by linking to static libs in release mode, and shared libs in debug mode...

+1 karoberts

John Weldon
Template code is blown out inline in Debug builds just like Release, so that is not likely to be the problem here.
John Dibling
Agreed, unless it's in a #if RELEASE or similar case.
John Weldon
I don't think so; a release compiler/optimizing can fold together template code to next to nothing. This is a huge size difference.
Terry Mahaffey
+1  A: 

No, this is not normal. It should be the other way around. Yes, you should care.

I'd start by looking at the sizes again, to make sure I didn't transpose the release and debug sizes somehow.

Then look at the libraries you're linking in for release and debug. Did you accidentially link a debug library to ship, and ship library to debug?

Take a close look at your settings for release and debug. Something very fishy is going on.

Terry Mahaffey
+1  A: 

Is it possible that a massive amount of this code is inline, and the debug version isn't "inlining"?

dicroce
+3  A: 

I would check to see if you're statically linking libraries in release mode and dynamically linking them in debug mode. You might be statically linking the C++ runtime for instance.

karoberts
+1: Been there.
Dathan
Assuming he is asking about a static library project, the static library is not ever linked with anything in the project. Linkage of static libraries only occurs whren the library is used.
anon
Correct Neil. No linking here, only external #includes
John
A: 

There is one thing that can explain such a size: debug symbols embedded in the release build (as opposed to built as a pdb). Are you sure you don't have debug symbols being generated for your release build ? (which visual c++ are you using?)

Bahbar
John
ok. culprit might be /Z7 and/or /Yd if using pch files. You might want to provide all the options you're using on your command line.
Bahbar
+2  A: 

I had the same problem. The fix is very simple. Project Property/Configuration properties/General/Whole Program Optimization use No Whole Program Optimization instead of Use Link Time Code Generation. Size of my static library decreased from 5MB to 1.3MB

rost
Not sure why, but this was the reason for me. It should not really be an issue unless you are deploying the .lib files somewhere. If you're just keeping them local to your solution, you should be alright because the .exe or .dll file that consumes the static lib will eliminate the stuff it doesn't need. My question: http://stackoverflow.com/questions/2472568/visual-c-9-0-2008-static-lib-boost-library-large-lib-file
CuppM