开发者

Turning on whole program optimization in some static library increases dramatically the library size !

In Visual Studio 2010, I have a C/C++ static library project. When I turn on the option whole program optimization in release mode, I obtain a .lib file exceeding 90 MB ! When I turn off this option the size is reduced to 24 MB. This library contains hundreds of classes generated with proto-buffer.

I'm wondering why this option increases the size ? Under which conditions we must turn it off ?

Edit : Changed MO to MB thanks chrisayc开发者_开发问答ock


Whole program optimization means things are not optimized until the link stage.

The size of a static library is not the thing to look at. When in this mode, the static library may be full of extra information needed for the final optimization/link stage. If you weren't doing whole program optimization then that information could have be thrown away after the static library was built, but when you are that information has to be kept until the end.

Look at the size of the final executable instead. (It may still increase, but it shouldn't increase by such a huge amount.)


I'm wondering why this option increases the size?

Because you are building a static library, not an executable. Whole Program Optimization leaves a lot of the optimization until link time (rather than at compile time). Thus, your library contains unoptimized "intermediate representation" rather than assembly code.

Under which conditions we must turn it off?

For static libraries, as you've just discovered.


Enabling whole program optimization lets linker to inline functions defined in implementation (*.cpp) files. Inlining the same function in many places can increase binary size significantly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜