简体   繁体   English

使用 VS2005 编译时巨大的 static 库文件,使用 gcc 编译时正常大小

[英]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.

相关问题 包括在使用vs2005的项目中在vs2010中编译的.lib文件 - including a .lib file compiled in vs2010 in a project that is using vs2005 QT Creator 上的应用程序如何调用使用 gcc 编译的静态库? - How an application on QT creator calls a static library compiled using gcc? 在VS2005上使用“--layout = system”时出现链接错误 - Boost link error when using “--layout=system” on VS2005 使用ext / hash_map在VS上的gcc编译库 - gcc compiled library on VS using ext/hash_map 静态库链接程序VS源代码编译程序巨大的差异 - Static Library linked Program VS Source Code Compiled program huge size difference 使用VS2013编译的应用程序需要VS2005运行时 - Application compiled with VS2013 wants VS2005 runtime Android 在编译二进制文件时重建 static 库 - Android rebuilds static library when the binary is compiled 在发布模式下编译时(VS 2005),不会发出QNetworkAccessManager完成的信号 - QNetworkAccessManager finished signal is not emitted when compiled in release mode (VS 2005) 在C ++中使用多重继承时无效的ESP(VS2005) - Invalid ESP when using multiple inheritance in C++ (VS2005) GCC编译的静态库包含什么? - What does a GCC compiled static library contain?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM