在某些静态库中打开整个程序优化会大大增加库的大小!

发布于 2024-10-09 16:35:46 字数 260 浏览 0 评论 0原文

在 Visual Studio 2010 中,我有一个 C/C++ 静态库项目。当我在发布模式下打开选项整个程序优化时,我获得了超过90 MB的.lib文件! 当我关闭此选项时,大小会减少到 24 MB。 该库包含数百个使用 proto-buffer 生成的类。

我想知道为什么这个选项会增加大小? 什么情况下我们必须关闭它?

编辑:将 MO 更改为 MB,感谢 chrisaycock

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 chrisaycock

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

倒带 2024-10-16 16:35:46

整个程序优化意味着直到链接阶段才进行优化。

静态库的大小不是重点。在此模式下,静态库可能充满最终优化/链接阶段所需的额外信息。如果您没有进行整个程序优化,那么在构建静态库后该信息可能会被丢弃,但是当您这样做时,该信息必须保留到最后。

相反,请查看最终可执行文件的大小。 (可能还会增加,但应该不会增加这么大。)

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.)

故事灯 2024-10-16 16:35:46

我想知道为什么这个选项
增加尺寸?

因为您正在构建静态库,而不是可执行文件。 整个程序优化将大量优化留到链接时(而不是编译时)。因此,您的库包含未优化的“中间表示”而不是汇编代码。

什么情况下我们必须转动它
关闭?

对于静态库,正如您刚刚发现的那样。

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.

朮生 2024-10-16 16:35:46

启用整个程序优化可让链接器链接到实现 (*.cpp) 文件中定义的内联函数。在许多地方内联相同的函数会显着增加二进制大小。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文