error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj

C++Visual Studio-2010Visual C++Msbuild

C++ Problem Overview


I was converting my projects from VS2010 to VS2012.But I am getting an _MSC_VER linker error in certain projects. After a long surfing through google I found out that the issue is due to linking of a library created in VS2010 to VS2012.

How can I find out that which projectis causing the error? Here I am quoting the error:

Error	6	error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj	  D:\ProjectLocation\Projectname1.lib(CppFile2.obj)	Projectname2
Error	15	error LNK2001: unresolved external symbol "private: static void __cdecl std::locale::facet::_Facet_Register(class std::locale::facet *)" (?_Facet_Register@facet@locale@std@@CAXPAV123@@Z)	D:\ProjectLocation\Projectname1.lib(CppFile3.obj)	Projectname2
Error	13	error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj	D:\ProjectLocation\Projectname1.lib(CppFile4.obj)	Projectname2
Error	12	error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj	D:\ProjectLocation\Projectname1.lib(CppFile5.obj)	Projectname2
Error	10	error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj	D:\ProjectLocation\Projectname1.lib(CppFile6.obj)	Projectname2
Error	11	error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj	D:\ProjectLocation\Projectname1.lib(CppFile7.obj)	Projectname2
Error	9	error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj	D:\ProjectLocation\Projectname1.lib(CppFile8.obj)	Projectname2
Error	4	error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj	   D:\ProjectLocation\Projectname1.lib(CppFile9.obj)	Projectname2
Error	14	error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj	D:\ProjectLocation\Projectname1.lib(CppFile10.obj)	Projectname2
Error	7	error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj	D:\ProjectLocation\Projectname1.lib(CppFile11.obj)	Projectname2
Error	8	error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj	D:\ProjectLocation\Projectname1.lib(CppFile12.obj)	Projectname2
Error	5	error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj	D:\ProjectLocation\Projectname1.lib(CppFile13.obj)	Projectname2

C++ Solutions


Solution 1 - C++

TL;DR; Recompile all your old static-linked .lib files with current-compiler (VS2012, in OP's case).


You are trying to link objects compiled by different versions of the compiler. That's not supported in modern versions of VS, at least not if you are using the C++ standard library. Different versions of the standard library are binary incompatible and so you need all the inputs to the linker to be compiled with the same version. Make sure you re-compile all the objects that are to be linked.

The compiler error names the objects involved so the information the the question already has the answer you are looking for. Specifically it seems that the static library that you are linking needs to be re-compiled.

So the solution is to recompile Projectname1.lib with VS2012.

>You can link to older .lib files only if: >* If they are not static-linked, and come with an already compiled .dll file (or .exe file). >* Or if the two standard-libraries are binary-compatible (which they are not in OP's case).

Solution 2 - C++

for each project in your solution make sure that

Properties > Config. Properties > General > Platform Toolset

is one for all of them, v100 for visual studio 2010, v110 for visual studio 2012

you also may be working on v100 from visual studio 2012

Solution 3 - C++

I was importing also some projects from VS2010 to VS 2012. I had the same errors. The errors disappeared when I set back Properties > Config. Properties > General > Platform Toolset to v100 (VS2010). That might not be the correct approach, however.

Solution 4 - C++

I upgraded from 2010 to 2013 and after changing all the projects' Platform Toolset, I need to right-click on the Solution and choose Retarget... to make it work.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmystackView Question on Stackoverflow
Solution 1 - C++David HeffernanView Answer on Stackoverflow
Solution 2 - C++Ahmed U3View Answer on Stackoverflow
Solution 3 - C++JinxiView Answer on Stackoverflow
Solution 4 - C++Hai TranView Answer on Stackoverflow