module unsafe for SAFESEH image C++

C++Visual StudioVisual C++

C++ Problem Overview


I am using 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.

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

> error LNK2026: module unsafe for SAFESEH image.

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.

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

C++ Solutions


Solution 1 - C++

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

Solution 2 - C++

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

Solution 3 - C++

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

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

Solution 4 - C++

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

Empty SEH handler:

.safeseh SEH_handler

SEH_handler   proc
;handler
ret
    
SEH_handler   endp

Solution 5 - C++

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

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

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

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAaron ThompsonView Question on Stackoverflow
Solution 1 - C++ZhenyaView Answer on Stackoverflow
Solution 2 - C++Bo PerssonView Answer on Stackoverflow
Solution 3 - C++Nayana AdassuriyaView Answer on Stackoverflow
Solution 4 - C++DitherSkyView Answer on Stackoverflow
Solution 5 - C++Bob StineView Answer on Stackoverflow