C++ 在 VC11 中启用/禁用 SAFESEH?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15982786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Enabling/disabling SAFESEH in VC11?
提问by RectangleEquals
I created a new solution for zlib 1.2.7, set it up as a static library, added the necessary headers and source files from ./zlib/contrib/minizip
and got it to compile just fine. I then linked it against libpng (also as a static lib), which also compiles fine. Then, I linked libpng to my graphics engine project (also a static library)... still no errors.
我为 zlib 1.2.7 创建了一个新解决方案,将其设置为静态库,添加了必要的头文件和源文件,./zlib/contrib/minizip
并使其编译得很好。然后我将它与 libpng(也作为静态库)链接,它也可以很好地编译。然后,我将 libpng 链接到我的图形引擎项目(也是一个静态库)......仍然没有错误。
But as soon as I link my main project to my graphics engine, I get several LNK2026 errors regarding crc32.obj, deflate.obj, inflate.obj, d3dxplane.obj, d3dxvec4.objand other zlib/directx related modules. It's telling me that they are coming from my graphics engine lib, so I've decided to fix this by adding /SAFESEH:NO
to my linker flags for the corresponding projects.
NOTE: I should probably state that all projects are set to target x86, NOT x64.
但是一旦我将我的主项目链接到我的图形引擎,我就会收到几个关于crc32.obj、deflate.obj、inflate.obj、d3dxplane.obj、d3dxvec4.obj和其他 zlib/directx 相关模块的LNK2026 错误。它告诉我它们来自我的图形引擎库,所以我决定通过添加/SAFESEH:NO
到相应项目的链接器标志来解决这个问题。
注意:我可能应该声明所有项目都设置为针对 x86,而不是 x64。
The problem, however, is now I'm getting:warning LNK4044: unrecognized option '/SAFESEH'; ignored
which results in the same LINK2026 errors in my main project.
If I open up a visual studio command prompt and type LINK /?
it confirms that /SAFESEH
is a valid linker option. I get the same error when I use /SAFESEH
(without the ':NO'), and if I omit it entirely then my main project simply refuses build.
但是,现在我遇到了问题:warning LNK4044: unrecognized option '/SAFESEH'; ignored
这会导致我的主项目中出现相同的 LINK2026 错误。
如果我打开一个 Visual Studio 命令提示符并输入LINK /?
它确认这/SAFESEH
是一个有效的链接器选项。我在使用/SAFESEH
(没有 ':NO')时遇到同样的错误,如果我完全省略它,那么我的主项目只是拒绝构建。
What's going on here? How do I get around this?
这里发生了什么?我该如何解决这个问题?
回答by Hans Passant
by adding /SAFESH:NO to my linker flags
通过将 /SAFESH:NO 添加到我的链接器标志
Well, you mis-spelled it. Maybe in your question, maybe in the linker settings, the kind of coincidence that tends to explain why something that should work doesn't work.
好吧,你拼错了。也许在您的问题中,也许在链接器设置中,这种巧合往往可以解释为什么应该起作用的东西不起作用。
It is available without having to type it in, do favor doing it that way. Project + Properties, Linker, Advanced, scroll down the right panel, "Image has Safe Exception Handlers" setting. Use the combobox to select No.
无需输入即可使用,请这样做。项目 + 属性、链接器、高级,向下滚动右侧面板,“图像具有安全异常处理程序”设置。使用组合框选择否。
回答by Nathan Ernst
A quick google showsthis indicates you need to recompile the offending modules with appropriate compiler settings.
快速谷歌显示这表明您需要使用适当的编译器设置重新编译有问题的模块。
Note that this flag is only works for x86 targets. If you're targeting 64-bit, you'll get this error regardless.
请注意,此标志仅适用于 x86 目标。如果您的目标是 64 位,无论如何您都会收到此错误。
Also, from http://msdn.microsoft.com/en-us/library/9a89h429(v=vs.80).aspx, which may be relevant:
此外,来自http://msdn.microsoft.com/en-us/library/9a89h429(v=vs.80).aspx,这可能是相关的:
The most common reason for the linker not to be able to produce an image is because one or more of the input files (modules) to the linker was not compatible with the safe exception handlers feature. A common reason for a module to not be compatible with safe exception handlers is because it was created with a compiler from a previous version of Visual C++.
链接器无法生成图像的最常见原因是链接器的一个或多个输入文件(模块)与安全异常处理程序功能不兼容。模块与安全异常处理程序不兼容的一个常见原因是因为它是使用早期版本的 Visual C++ 的编译器创建的。
It would be helpful if you provided version numbers of your compiler, and how your copy of zlib was built (did you build it yourself, and if so, with the same compiler?).
如果您提供编译器的版本号,以及您的 zlib 副本是如何构建的(您是否自己构建它,如果是,使用相同的编译器?),将会很有帮助。
回答by Roman M
In Visual Studio 2017
Right click on Project -> Properties -> Configuration Properties -> Linker -> All Options ->
Image Has Safe Exception Handlers = No (/SAFESEH:NO)
在 Visual Studio 2017 中右键单击 Project -> Properties -> Configuration Properties -> Linker -> All Options -> Image Has Safe Exception Handlers = No (/SAFESEH:NO)