Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling/disabling SAFESEH in VC11?

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.

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.obj and 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.

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.

What's going on here? How do I get around this?

like image 204
RectangleEquals Avatar asked Apr 13 '13 00:04

RectangleEquals


2 Answers

by adding /SAFESH:NO to my linker flags

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.

like image 110
Hans Passant Avatar answered Oct 21 '22 11:10

Hans Passant


A quick google shows this 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.

Also, from http://msdn.microsoft.com/en-us/library/9a89h429(v=vs.80).aspx, which may be relevant:

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++.

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?).

like image 36
Nathan Ernst Avatar answered Oct 21 '22 11:10

Nathan Ernst