禁用可执行文件中的优化并将其维护在静态库中
我遇到了一种奇怪的情况,我(假设的)代码链接知识让我失败了...
我遇到了一个错误,该错误仅发生在打开优化的 64 位构建中(/O2、/O3 或/牛)。该错误发生在对性能不关键的可执行文件中,我们必须很快(即星期一)提供原型演示。由于在演示中实现此功能的巨大压力,我有了一个想法;构建启用优化的静态库(这对性能至关重要),并在可执行文件中将其关闭。这应该隐藏错误,直到我修复它,同时不会减慢系统速度,或者我是这么认为的。
我现在已经尝试过关闭和打开“链接时间代码生成”,并且没有整个程序优化,但每次使用 VS2005 C++ 编译器以及使用 Intel 编译器时,性能关键库都不会与启用优化后,速度会急剧下降。
有谁知道如何实现我在这里追求的目标?这是一个奇怪的情况,我从来没有处理过它,但我做了一些阅读,我找不到任何文档说我想要完成的事情是不可行的,但显然它不是或者我错过了某物。预先感谢你们可以提供的任何帮助,我知道这是对肮脏的短期“修复”的奇怪请求,但它相当重要。
I've come across an odd situation and my (supposed) knowledge of code linkage is failing me...
I have come across a bug that only occurs in a 64-bit build with optimizations turned on (/O2, /O3, or /Ox). The bug occurs in an executable that is not performance critical and we have to give a demo of a prototype very soon (i.e., Monday). Due to the extreme pressure to get this working for the demo, I had an idea; build the static library (which is performance critical) with optimizations on and turn them off in the executable. This should hide the bug until I fix it while not slowing down the system, or so I thought.
I have now tried this with Link Time Code Generation off, as well as on, and no whole program optimization, but each time, with the VS2005 C++ compiler as well as when using Intel's compiler, the performance critical library is not being linked in with optimizations enabled and things slow down dramatically.
Does anyone know how to accomplish what I am after here? This is an odd situation and I have never had to deal with it, but I did some reading and I couldn't find any documentation saying that what I am trying to accomplish isn't feasible, but apparently it is not or I am missing something. Thanks in advance for any help you guys can offer, I know this is an odd request for a dirty short term "fix", but it is rather important.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的问题几乎可以肯定是通过关闭优化在最终应用程序中禁用了库或标准库中函数的关键内联。
Your problem is almost assuredly that critical inlining of functions in your library or the standard library is being disabled in the final application by turning off optimizations.
我猜想您的未优化 EXE 实际上并未与优化静态库链接。
如果您知道优化正在运行哪个函数,您可以做的就是在该函数周围使用编译指示来关闭针对它的优化。
I would guess that your non-optimized EXE is not actually being linked with the optimized static lib.
If you know what function the optimization is borking, something you can do is use pragmas around that function to turn off optimizations just for it.
“未在启用优化的情况下链接”这一说法有点令人困惑,因为这应该是不可能的;链接器将链接编译器生成的任何内容。如果在编译静态库中的模块时正确设置编译器标志,那么它们都应该被优化。
问题可能是您的静态库正在调用 C++ 库中未优化的函数。您对此无能为力,因为应用程序和库必须都使用相同的 C++ 库,否则您将遇到比开始时更严重的问题。
The statement "is not being linked in with optimizations enabled" is a bit confusing, as this should be impossible; the linker will link whatever the compiler generated. If you set the compiler flags properly when compiling the modules in the static library, then they should all be optimized.
The problem might be that your static library is calling functions from the C++ library that are not optimized. There is nothing you can do about this, since the application and the library must both use the same C++ library or you will have much worse problems than you started with.