模块对于 SAFESEH 图像 C++ 不安全

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10599940/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:15:55  来源:igfitidea点击:

module unsafe for SAFESEH image C++

c++visual-studiovisual-c++

提问by Aaron Thompson

I am using Microsoft Visual Studio 2011 Professional Beta

我使用的是 Microsoft Visual Studio 2011 Professional Beta

I am trying to run the OpenCV C++ files (http://opencv.willowgarage.com/wiki/Welcome) that I have compiled using cMake & the Visual Studio Complier.

我正在尝试运行我使用 cMake 和 Visual Studio Complier 编译的 OpenCV C++ 文件 ( http://opencv.willowgarage.com/wiki/Welcome)。

However when I go to debug the project I get 600+ errors most of them being:

但是,当我去调试项目时,我收到了 600 多个错误,其中大部分是:

error LNK2026: module unsafe for SAFESEH image.

错误 LNK2026:模块对于 SAFESEH 图像不安全。

Apparently these files are in the opencv_ffmpeg project but I couldn't find them, I have had a look at the safeseh Safe Exception Handlers page on the Microsoft help page but I couldn't find any definitive answers.

显然这些文件在 opencv_ffmpeg 项目中,但我找不到它们,我查看了 Microsoft 帮助页面上的 safeseh Safe Exception Handlers 页面,但找不到任何明确的答案。

I was wondering if anyone else has had this problem and if they managed to fix it.

我想知道是否有其他人遇到过这个问题,他们是否设法解决了这个问题。

采纳答案by Bo Persson

From the comments:

来自评论:

This happens when you link an .obj or .lib that contains code created by an earlier version of the compiler. Which of course would be common if you downloaded a binary for opencv_ffmpeg instead of the source. You can turn the linker option off but then you'll still have a CRT version incompatibility that can byte. Rebuild the library from source. –?Hans Passant May 15 at 13:01 ?
?
Thanks for the help, it worked –?Aaron Thompson May 17 at 14:50

当您链接包含由早期版本的编译器创建的代码的 .obj 或 .lib 时,会发生这种情况。如果您下载了 opencv_ffmpeg 的二进制文件而不是源文件,这当然很常见。您可以关闭链接器选项,但是您仍然会遇到可以字节的 CRT 版本不兼容性。从源代码重建库。–?Hans Passant 5 月 15 日 13:01 ?
?
感谢您的帮助,它奏效了 –?Aaron Thompson 5 月 17 日 14:50

回答by Zhenya

Disabling option "Image has Safe Exception Handlers" in Project properties -> Configuration Properties -> Linker -> Advanced tab helped me.

在项目属性 -> 配置属性 -> 链接器 -> 高级选项卡中禁用选项“图像具有安全异常处理程序”对我有帮助。

回答by Nayana Adassuriya

If you got this error while building ZLIB in Visual Studio here is the solution. Look for contrib\masmx86\bld_ml32.batand add /safesehas a option

如果在 Visual Studio 中构建 ZLIB 时遇到此错误,这里是解决方案。查找contrib\masmx86\bld_ml32.bat并添加/safeseh为选项

Before

ml /coff /Zi /c /Flmatch686.lst match686.asm
ml /coff /Zi /c /Flinffas32.lst inffas32.asm

After

ml /safeseh /coff /Zi /c /Flmatch686.lst match686.asm
ml /safeseh /coff /Zi /c /Flinffas32.lst inffas32.asm

回答by DitherSky

Other way is to add some SEH handler (empty for example) to asm files and compile them with /safesehoption, then compile other code normally with /SAFESEH:YEScompiler option.

另一种方法是在 asm 文件中添加一些 SEH 处理程序(例如空)并使用/safeseh选项编译它们,然后使用/SAFESEH:YES编译器选项正常编译其他代码。

Empty SEH handler:

空 SEH 处理程序:

.safeseh SEH_handler

SEH_handler   proc
;handler
ret

SEH_handler   endp

回答by Bob Stine

Your mileage may vary, but none of the above suggestions worked for me (although I did not try rolling my own asm exception handler).

您的里程可能会有所不同,但上述建议均不适合我(尽管我没有尝试滚动自己的 asm 异常处理程序)。

What did work was to select build target Release/x64.

有效的是选择构建目标 Release/x64。

I am running Windows 10 on a 64-bit machine, and using Visual Studio 2015.

我在 64 位机器上运行 Windows 10,并使用 Visual Studio 2015。

The target Release/Win32 works, too. I guess the main thing is to pick "Release".

目标 Release/Win32 也可以工作。我想主要是选择“发布”。