Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Unresolved external symbol __except_handler4_common" in Visual Studio 2015

I'm compiling a legacy Visual Studio 6.0 C++ application in Visual Studio 2015 and I've run into this error and searching the net hasn't yielded any useful information.

LNK2019 unresolved external symbol __except_handler4_common referenced in function __except_handler4 (MSVCRT.lib)

I understand that somewhere in the code is referencing a method no longer(?) present in current versions of MSVCRT. Is there a workaround / compiler flag for this?

like image 829
Mr. Awesome Avatar asked Aug 06 '15 22:08

Mr. Awesome


People also ask

How do you fix unresolved externals?

So when we try to assign it a value in the main function, the linker doesn't find the symbol and may result in an “unresolved external symbol” or “undefined reference”. The way to fix this error is to explicitly scope the variable using '::' outside the main before using it.

What causes unresolved external symbol?

Answer. Unresolved external references occur when the symbol for a function or global variable is referenced in a program, but none of the object files or libraries specified in the link step contain a definition for that symbol.


4 Answers

In your library project, check Properties -> C/C++ -> Code Generation -> Runtime Library

Chances are it's set to "Multi Threaded Debug DLL" (/MDd).

If that's the case then try changing it to "Multi Threaded Debug" (/MTd) and rebuild (that worked for me).

like image 41
Den-Jason Avatar answered Oct 20 '22 22:10

Den-Jason


The error message is actually saying the the function __except_handler4, defined in MSVCRT.LIB, references the undefined symbol __except_handler4_common. So it's not your code that's making the this reference, it's Visual Studio 2015's code.

The symbol __except_handler4_common is defined in vcruntime.lib. This file should be automatically be linked in. I'm not sure why it wasn't. Did you select the static runtime library in the project options ("Multi-threaded (/MT)"), but then manually add MSVCRT.LIB (part of the dynamic C runtime libary)?

like image 183
Ross Ridge Avatar answered Oct 21 '22 00:10

Ross Ridge


The reason for this error depends.

For me it was "libcmt.lib" and "libcmtd.lib" listed explicitly among linker inputs, rather than by selecting it from "Runtime Library" field in GUI.

like image 4
Serge Rogatch Avatar answered Oct 21 '22 00:10

Serge Rogatch


For me, I was linking to the objects of a static project from a non-static unit test. I tried setting the unit test to static build, but then the compiler (VC++ 2015) got the error An internal error has occurred in the compiler. I ended up setting both the main project and the unit test project to "Use MFC in a Shared DLL", and then it worked.

like image 3
Michael Avatar answered Oct 20 '22 23:10

Michael