54

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.

CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
Hoai Dam
  • 658
  • 2
  • 7
  • 13

3 Answers3

93

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)"
kungfooman
  • 4,473
  • 1
  • 44
  • 33
47

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.

chappjc
  • 30,359
  • 6
  • 75
  • 132
40
Try to disable SAFESEH.

From spec: /SAFESEH was specified, but a module was not compatible with the safe exception handling feature.

Leo Chapiro
  • 13,678
  • 8
  • 61
  • 92
  • 1
    I got it, thanks! But is every assembly-based mudule unsafe ? And where can I search for the standard of a SAFE module ? – Hoai Dam Feb 05 '13 at 15:24
  • 4
    Take a look at this article: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/ec2b66ec-f1a3-49fb-a8df-329965239284/ HTH – Leo Chapiro Feb 05 '13 at 15:34
  • @LeoChapiro thanks! From there (Mike Danes): 「But it seems that it is easy to make masm generate a safeseh object file, just set the Use Safe Exception Handler MASM property to Yes (see Project Properties, Microsoft Macro Assembler, Advanced). • See also the `.safeseh` MASM directive here: https://learn.microsoft.com/en-us/cpp/assembler/masm/dot-safeseh?view=msvc-150 but probably you don't need it because your assembly code doesn't really contain any exception handlers.」 (link fixed) – mirabilos Jan 26 '22 at 10:19