"Unresolved external symbol __except_handler4_common" in Visual Studio 2015 - c++

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?

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

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

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.

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.

Related

Linker Tools Error while configured and build wxWidgets Visual Studio 2017

Not able to configure wxwidgets in Visual Studio 2017.
Followed these steps.
From wxwidgets website, downloaded Source Code 'Windows 7Z' file, Version 3.1.3.
Run the wx_vc15.sln from build ->msw in Visual Studio 2017.
Build the Debub, DLL Debug, DLL Release, Relese successfully with Platform x86.
In Microsoft Visual Studio 17 V15.9.20, created an empty project. Added a simple wxWidgets program.
In project properties made the below changes
- In All Configurations with Platform Win32, Set the Configuration Properties -> Character Set to Use Unicode Character Set
C/C++ -> Additional Include Directories -> $(WXWIN)\include\msvc;$(WXWIN)\include;
C/C++ -> Preprocessor -> Preprocessor Defenitions -> __WXMSW__;WXUSINGDLL;_DEBUG
Linker -> Additional Library Directories -> $(WXWIN)\lib\vc_dll
Made these changes in Environment Variables
In User variables
Add a new variable WXWIN and set its value to C:\Users\varun\Desktop\workspace\wxWidgets-3.1.3.
Path -> C:\Users\varun\Desktop\workspace\wxWidgets-3.1.3\lib\vc_dll.
In project properties Release Configurations, made these changes
C/C++ -> Preprocessor -> Preprocessor Defenitions -> __WXMSW__;WXUSINGDLL;NDEBUG;
There is no code error but Linker Tools Error
Error (active) E1097 unknown attribute "no_init_all" WxWidgets_Application_5 C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winnt.h
Error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main##YAHXZ) WxWidgets_Application_3 C:\Users\varun\Desktop\workspace\visual_studio_projects_2017\WxWidgets_Application_3\WxWidgets_Application_3\MSVCRTD.lib(exe_main.obj)
Error LNK1120 1 unresolved externals WxWidgets_Application_3 C:\Users\varun\Desktop\workspace\visual_studio_projects_2017\WxWidgets_Application_3\Debug\WxWidgets_Application_3.exe
What could have gone wrong?
The first error you show is not an error at all but just some IntelliSense noise, see this bug report. The real error is not being able to find _main which seems to indicate that you're building a console application (see Properties\Linker\System\SubSystem option), so it should be fixed by just making it a Windows application instead.
Also, while I don't see anything really wrong with your setup, I would still recommend using the official instructions instead. Notably in your case it should be as simple as:
If you use MSVS 2010 or later IDE for building your project, simply add wxwidgets.props property sheet to (all) your project(s) using wxWidgets. You don't need to do anything else.

memcmp linker error Visual Studio 2015

I have a visual studio 2012 c++ project.
I recently uninstalled it and installed visual studio 2015 and upgraded the project.
When i am building the project, getting error as shown below:
Error LNK2019 unresolved external symbol _memcmp referenced in function
Moreover i have not used anywhere in my code memcmp fucntion.
I used the linker verbose function and could see below in output file:
Found _memcmp
Referenced in MyC++Project.obj
Referenced in libcpmtd.lib(xstrcoll.obj)
Loaded libvcruntimed.lib(__memcmp_.obj)
Two questions here
1.even though i have not used memcmp in my code why i am getting that linker error?
2.why is memcmp being loaded as __memcmp_.obj
I have the following settings also in my project:
1.C++-->Code generation-->Runtime Library is set to /MTd
2.Linker-->Ignore All default libraries is set to nothing
I have tried all the project settings but everything in vain.
I have issue only with this memcmp function which i have not used.
I have used mamcpy and memset and do not have issue with those
Explicitly add vcruntime.lib or other appropriate version of CRT Library to linker parameters (additional dependencies).
When you use memcmp explicitly it is probably handled as intrinsic function and is compiled as inline function.
Try to add vcruntime.lib and ucrt.lib to your additional dependencies. ===> properties->Linker->Input->Additional Dependencies
Sample path of 'vcruntime.lib': "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\vcruntime.lib"
Sample path of 'ucrt.lib' : "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\ucrt\x86\ucrt.lib"
My environment: VS2017 (v141)
I've run into this same problem with a legacy Visual C++ 6.0 nmake file with Visual Studio 2015.
This blog article, Introducing the Universal CRT, describes how the Visual Studio 2015 runtime has been split into more than one library. The runtime is now "split the CRT into two logical parts: The VCRuntime, which contained the compiler support functionality required for things like process startup and exception handling, and a “stable” part that contained all of the purely library parts of the CRT" to allow for easier updates.
So long as you do not link with the /nodefaultlib option, all of the
correct library files will be found when you link your project. If you
link with the /nodefaultlib option, you will need to link several
extra libraries when you link. For example, whereas you previously
might have just linked msvcrt.lib in order to use the CRT DLL, you
will now also need to link vcruntime.lib and ucrt.lib. Here is a table
that shows which libraries you will need to link for each “flavor” of
the libraries:
Release DLLs (/MD ): msvcrt.lib vcruntime.lib ucrt.lib
Debug DLLs (/MDd): msvcrtd.lib vcruntimed.lib ucrtd.lib
Release Static (/MT ): libcmt.lib libvcruntime.lib libucrt.lib
Debug Static (/MTd): libcmtd.lib libvcruntimed.lib libucrtd.lib
See also the Microsoft documentation C runtime (CRT) and C++ Standard Library (STL) .lib files which describes details about the libraries.
See also Microsoft C/C++ change history 2003 - 2015.

Unknown external symbol _WinMainCRTStartup

I've been trying to solve this linker error for the last 3 hours, I keep getting errors saying that I have unresolved external symbol of _WinMainCRTStartup. Does anyone know what could be causing this error? I am using SDL's main function definition (SDL_main)
I also tried recreating the project incase something was accidentally changed, but the error persists.
The full output is here
https://gist.github.com/Joshhua5/73fe4235724d95e53f48
You're getting lots of unresolved external symbols, not just _WinMainCRTStartup. This usually indicates you're not linking a library you need to, and given the names of the functions it looks like it's the C runtime library (controlled with the /MTd etc. flags, or "C/C++ -> Code Generation -> Runtime Library" in the project properties dialogue.
I think I see the problem though; this line near the bottom:
4>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\OLDNAMES.lib : warning LNK4272: library machine type 'UNKNOWN' conflicts with target machine type 'X86'
... suggests you're using the VS2015 preview, and I don't imagine there's a release of SDL for that toolset yet, so I guess you're linking old libraries (which expect to be linked with an older toolset). Is that right? If so, you'll need to build SDL yourself.
Another possibility is simply that you've got the wrong subsystem type set - SDL will be expecting either /SUBSYSTEM:CONSOLE or /SUBSYSTEM:WINDOWS (set in "Linker -> System -> SubSystem"). Try choosing whichever one isn't chosen now.

Failed to use C++ Rest SDK and Microsoft unit test at the same time

I have a MFC project which uses C++ Rest SDK (Casablanca) under Visual Studio 2012 to implement an http client connection and it can be compiled well.
Then I add a Microsoft unit test project, but I can’t build the unit test project successfully.
In my main project, the environment is set as “Use MFC in a Static Library”, “No Common Language Runtime Support” and “Multi-threaded Debug (/MTd).” And my test project’s environment is same as main project. The error message shows:
“error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U#YAPAXI#Z) already defined in libcpmtd.lib(newaop.obj).”
In addition, I also try to change the test project’s environment to “Common Language Runtime Support (/clr)” and “Multi-threaded Debug DLL (/MDd).” The original error disappears but new error comes:
“error C1189: #error : is not supported when compiling with /clr or /clr:pure. c:\program files (x86)\microsoft visual studio 11.0\vc\include\atomic line 9”
I do not know how to overcome these problems. Can anyone please give me some suggestions or resolutions? Thanks.
The CRT libraries use weak external linkage for the new, delete functions. The MFC libraries also contain new, delete functions. These functions require the MFC libraries to be linked before the CRT library is linked. Please check http://support.microsoft.com/kb/148652
Solution based on VS2005:
go to project>properties>configuration properties>linker>input
add to "Additional dependency" -> Nafxcwd.lib Libcmtd.lib
add to "ignore specific library" -> Nafxcwd.lib;Libcmtd.lib
I have found that by using NuGet Packmanager to get rest sdk i.e. Search for Casablanca and select cpprestsdk.v140.windesktop. This makes sure all the dlls, libs required are referenced.
Please check:
https://github.com/Microsoft/cpprestsdk/wiki/How-to-use-the-C---Rest-SDK-NuGet-package
http://codename26.rssing.com/chan-8623770/all_p85.html

visual studio 2010 express linking file in different projects

in visual studio 2010 express edition. i have a project (a static library) called prj1.
prj1 has codes to create an object obj1.
in another project prj2 which is a dynamic library i have code which intantiates the object by "new obj1" (the code of obj1 is in prj1).
now when i try to build prj2 i get linking errors:
1> when i try to right click on prj2->properties->frameworkk and references if i add prj1 as new reference i get a lot of link errors like MSVCRTD.lib(MSVCR100D.dll) : error LNK2005:
2> if i do not do step1 above and right click on the solution->properties->project dependencies and then choose prj1 to depend on the prj2. then i get just get a link error which complains that : error LNK2019: unresolved external symbol obj1... unresolved externals.
It would be very kind if someone can help me resolve this issue.
Thanks
Seems that your options that choose runtime library differ. One project for example links to "multi-threaded debug DLL" and other project to "multi threaded debug". When you try to link the projects to each other then you get multiply defined runtime library symbols.
Your static library must be found/added to your library directories, and dependency list, too.