"Unable to generate SAFESEH image." but disabling SAFESEH breaks dependency links

44 views Asked by At

My code builds fine in Release configuration in Visual Studio, but when I set it to the Debug config it throws two errors (one and four times):

LNK1281 Unable to generate SAFESEH image.
LNK2026 module unsafe for SAFESEH image.

enter image description here

Naturally, I came here looking for answers and everyone seems to be of the consensus to turn it off in VS project properties:

Image has Safe Exception Handlers     No (/SAFESEH:NO) 

BUT, that breaks a link to my dependencies. It builds without errors, but it can't find the external libraries during runtime. I have the paths to them set up in the solution properties. I do not have the ability to edit those library suites.

What are my options to get past this issue? Searches have come up short.

This is one example of the error popups, but there are several others (including HawkNL.dll in the error above):

enter image description here


1

There are 1 answers

0
LazyBear On

After consulting with a helpful colleague, he suggested running Microsoft Depends (Dependency Walker). So I disabled SAFESEH (/SAFESEH:NO) and ran it through Depends. As expected, despite being linked correctly in the properties of the project, the dependencies that were "not found" were not linking during runtime in Depends either. But it did give us exactly where Visual Studio was looking and found it wasn't looking where it should.

So we just copied the "lost" dependencies/DLLs right into the Debug build folder with the executable. The project was able to find the dependencies and run the application in debug. So, even know I still don't know why the dependency link was lost, it works now.