Release LIB is huge compared to debug


VC生成静态库release版比debug版库文件尺寸更大,

此问题是由VS的Build选项中Optimization项下的Whole Program Opeimization选项不同设置引起:


Debug版的此选项缺省设成No,而Release版的此选项缺省设成Enable link-time code generation (/GL)
由于静态库并不进行链接,而全局优化要等到链接时,所以release版产生的库文件就要比debug版的大上不少了。


Release LIB is huge compared to debug

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?

share | improve this question
 
   
You are asking about a static library project, right? –  anon Jan 12 '10 at 20:59
   
yes, sorry. edited to clarify. –  Mr. Boy Jan 12 '10 at 21:17
   
I have this problem now. Did you find the reason? –  Sam Goldberg Aug 6 '13 at 17:31

7 Answers 7

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.

share | improve this answer
 
   
+1: Been there. –  Dathan Jan 12 '10 at 20:48
   
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 Jan 12 '10 at 21:00
   
Correct Neil. No linking here, only external #includes –  Mr. Boy Jan 12 '10 at 21:18
                    

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

share | improve this answer
 
   
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: stackoverflow.com/questions/2472568/… –  CuppM Mar 23 '10 at 16:30

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.

share | improve this answer
 
 

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

share | improve this answer
 
 

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.

share | improve this answer
 
 

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

share | improve this answer
 
   
Template code is blown out inline in Debug builds just like Release, so that is not likely to be the problem here. –  John Dibling Jan 12 '10 at 20:40
   
Agreed, unless it's in a #if RELEASE or similar case. –  John Weldon Jan 12 '10 at 20:40
   
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 Jan 12 '10 at 20:40

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?)

share | improve this answer
 
   
2008. PDB/debug info is an area I plan to look at closely... I generally do generate PDB for release & debug, but that should be a separate file. –  Mr. Boy Jan 12 '10 at 21:19
   
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 Jan 12 '10 at 21:35


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值