[英]Huge static library file when compiled using VS2005, normal size when compiled using gcc
I'm compiling a static library that contains mainly templated classes.我正在编译一个主要包含模板类的 static 库。 When this is compiled using gcc, the resulting.a file is around about the 40Mb mark.
当使用 gcc 编译时,生成的.a 文件大约为 40Mb 标记。 This is pretty big, but not entirely unexpected due to the amount of templating going on.
这是相当大的,但由于模板的数量,这并不完全出乎意料。 However, when I compile the same code using VS2005, the resulting.lib file is coming in at (wait for it.) 575Mb..
但是,当我使用 VS2005 编译相同的代码时,resulting.lib 文件进入(等待它。)575Mb ..
Now, before I get burned, I have seen: How can I get my very large program to link?现在,在我被烧毁之前,我已经看到: 我怎样才能让我的非常大的程序链接? and this is useful for understanding that templates are potentially making the libs large, but I'm struggling to understand why the outputs from the two compilers are so different in size?
这对于理解模板可能会使库变大很有用,但我很难理解为什么两个编译器的输出大小如此不同?
VS options are: (Debug) VS选项是:(调试)
/Od /D "WIN32" /D "_DEBUG" /D "_LIB" /D "_WIN32_WINNT=0x0500" /D "_MBCS" /Gm /EHsc /RTC1 /MDd /W4 /nologo /c /Wp64 /Zi /TP /errorReport:prompt
(Release) (发布)
/O2 /D "WIN32" /D "NDEBUG" /D "_LIB" /D "_WIN32_WINNT=0x0500" /D "_MBCS" /FD /EHsc /MD /W4 /nologo /c /Wp64 /Zi /TP /errorReport:prompt
Any comments or pointers are much appreciated..任何意见或指针都非常感谢..
A debug build disables inlining and also the linker options that discard duplicate code, so you get lots of copies of every template and inline function.调试版本禁用内联以及丢弃重复代码的 linker 选项,因此您可以获得每个模板和内联 function 的大量副本。
You can enable it with /OPT:REF /OPT:ICF
in your linker options.您可以在 linker 选项中使用
/OPT:REF /OPT:ICF
启用它。 But it should be there by default in a release build.但它应该在发布版本中默认存在。
Unfortunately I think that only helps with your final executable, not the intermediate library.不幸的是,我认为这只有助于您的最终可执行文件,而不是中间库。
You might be able to save some space by explicitly instantiating the template instances you need in one.cpp, and using extern template to prevent automatic instantiation when compiling other source files.您可以通过在 one.cpp 中显式实例化您需要的模板实例来节省一些空间,并在编译其他源文件时使用extern 模板来防止自动实例化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.