Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error lnk2026: module unsafe for safeseh image

I got this error when building a sample visual C++ project. First I downloaded 3 sample projects, all solve the same problem, print out all the prime numbers less than N (you may know these sample projects ?). I built the pure-C project without any problem. But when I tried to build the assembly-based project one, I got this error.

Thank you.

like image 439
Hoai Dam Avatar asked Feb 05 '13 15:02

Hoai Dam


People also ask

How do I turn off safeseh?

Turn off SAFESEH by opening your project properties, going to Linker > Advanced and setting Image Has Safe Exception Handlers to No.

What is safeseh?

SafeSEH (Safe Structured Exception Handlers) is a Windows binary protection mechanism for 32-bit executables that has been around for a while now. When the option is enabled, the linker creates a list of valid exception handler addresses in the SEHandlerTable when the binary is being built.


2 Answers

In Visual Studio 2012 Express Edition:

Right-click on your project -> Properties ->  Configuration Properties -> Linker -> Advanced and changed "Image Has Safe Exception Handlers" to "No (/SAFESEH:NO)" 
like image 173
kungfooman Avatar answered Sep 28 '22 05:09

kungfooman


A picture is worth 0x3e8 words for the /SAFESEH:NO linker setting:

enter image description here

Or you can tell MASM to provide a guarantee that the object contains no exception handlers or that any exception handlers are defined with .SAFESEH, if you know that to be correct for your assembly code:

enter image description here

This will allow you to keep /SAFESEH enabled for the project's linking. But is it correct? You are making the guarantee! Be sure or use the first option.

like image 35
chappjc Avatar answered Sep 28 '22 05:09

chappjc