为什么我的静态库如此巨大? [英] Why is my static library so huge?

查看:201
本文介绍了为什么我的静态库如此巨大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个约15个类的C ++编译静态库及其成员函数和东西,编译后,它几乎是14兆字节。它链接到Google的密集哈希表库和MPIR,这就像GMP for Windows,但我做了一个简单的exe,它是几个千字节。为什么这么大?我可以做什么来减小它的大小?

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.

使用Visual C ++编译,命令行是:

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


推荐答案

静态库是一个完全不同的格式完成的二进制;部分是因为它有更多的信息。基本上,静态库就像从您的翻译单元生成的所有.obj文件的ZIP。这允许链接器抛出未使用的函数,如果你使用LTCG,它允许内联进行跨模块决策和其他这样的优化。

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.

此外,一些编译模式将直接在.lib中嵌入调试符号,从而不需要单独的.pdb文件。

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.

这篇关于为什么我的静态库如此巨大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆