开发者

Why is my static library so huge?

I have a C++ compiled static library of about 15 classes and their member functions and stuff, and compiled, it's almost 14 megabytes. It links to Google's dense hash table library and MPIR, which is like GMP for Windows, but I did that in a plain exe and it was a few kilobytes. Why is it so massive? What can I do to reduce its size? It seems like there's other programs which are far more complicated than mine that are far smaller.

Compiled with Visual C++, command line is:

/Zi /nologo /W3 /WX- /O2 /Oi /Oy- /GL /D "WIN32" /D "NDEBUG" /D "_CONSOLE"
/D "_UNICODE" /D "UNICODE" /Gm- /EHsc /GS /Gy /fp:precise /Zc:wchar_t
/Zc:forScope /Fp"Release\ang.pch" /Fa"Release\" /Fo"Release\"
/Fd"Release\vc100.pdb" /Gd /analyze-开发者_开发问答 /errorReport:queue


The static library is a considerably different format the finished binary; partially because it has quite a bit more information. Essentially, the static library acts like a ZIP of all the .obj files generated from your translation units. This allows the linker to throw out unused functions, and if you're using LTCG, it allows the inliner to make cross-module decisions and other such optimizations.

Additionally, some compilation modes will embed the debugging symbols directly in the .lib, removing the need for separate .pdb files.

Generally you shouldn't need to worry about static library size; the linker will throw out all the extra information when building the final executable.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜