Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is __CxxFrameHandler4 and what does linker error "unresolved external symbol __CxxFrameHandler4" mean, exactly?

I'm using several libraries built through vcpkg (such as civet-web and prometheus-cpp), against my Visual C++ projects. When building x86 all is perfect, in x64 I get a bunch of linker errors:

error LNK2001: unresolved external symbol __CxxFrameHandler4

Searching online all references to this symbol/error are about specific projects, I cannot find what __CxxFrameHandler4 is and what problem this error is highlighting. I don't know if it's a problem with the way vcpkg is building the library, or a problem in my project or how to start looking for a solution.

I did find this blog article but it is in reference to a preview of VS2019, I cannot find any settings related to it: https://devblogs.microsoft.com/cppblog/making-cpp-exception-handling-smaller-x64/

If anyone can explain what this is all about it would be a big help.

like image 595
Mr. Boy Avatar asked Jan 11 '21 18:01

Mr. Boy


People also ask

What is __ cxxframehandler4?

__CxxFrameHandler4 indicates that the library is building with the VS 2019 x64 toolset (19.20 - 19.28), but is being linked against an older version of the Visual C++ Runtime. The binary compatibility story for VS 2015/2017/2019 only works if the final link is done by the 'newest' toolset in the mix.

How do I fix unresolved external symbol?

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.

How do I fix unresolved external symbol lnk2001?

To fix this issue, add the /NOENTRY option to the link command. This error can occur if you use incorrect /SUBSYSTEM or /ENTRY settings in your project. For example, if you write a console application and specify /SUBSYSTEM:WINDOWS, an unresolved external error is generated for WinMain .


3 Answers

I faced the same issues when trying to install and use cpr with vcpkg. I wanted to use cpr library in a VS2015 project.

Reason: I had VS2019 installed. vcpkg uses latest version of toolset Visual Studio.
Resolution: Add your own triplet or change existing such a way that your specified toolset is used. Adding did not work in my case so I changed existing "triplet" files in triplet folder in vcpkg. I wanted vcpkg to use toolset that comes with VS2015 (It's V140)

Content of x86-windows.cmake file

set(VCPKG_TARGET_ARCHITECTURE x86)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_PLATFORM_TOOLSET "v140")
set(VCPKG_DEP_INFO_OVERRIDE_VARS "v140")

Content of x64-windows.cmake file

set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_PLATFORM_TOOLSET "v140")
set(VCPKG_DEP_INFO_OVERRIDE_VARS "v140")
like image 104
Rupesh Bhurke Avatar answered Oct 21 '22 02:10

Rupesh Bhurke


I think you pointed out the right article which is https://devblogs.microsoft.com/cppblog/making-cpp-exception-handling-smaller-x64/

I faced a similar issue in linking 64-bit library built with VC143 toolset with a 64-bit Application built with VC141 toolset.

After adding the following properties to VC143 built static library project, I was able to build the application. This disables the new feature mentioned in the above article (Exception Handling Smaller)

VS2019->Properties->C/C++->Command Line add '-d2FH4-'
VS2019->Properties->Linker->Command Line add '-d2:-FH4-' 
like image 25
Sowrab B M Avatar answered Oct 21 '22 02:10

Sowrab B M


A more general answer is that this happens if you are mixing objects that were built with different platform toolsets, e.g.,

  • Visual C++ 2015 (v140)
  • Visual C++ 2017 (v141)

Typically, you (or someone else) may have built a dependency of your project with a different compiler version (platform toolset), and the fix it to change the platform toolset of either your project or the dependency (or use the correct build of the dependency, if you used a pre-built package)

like image 25
Florian Winter Avatar answered Oct 21 '22 04:10

Florian Winter