How can i fix error LNK2038 after adding tinyxml2? - c++

I have a project that compiles normally and i need to use tinyxml2 library in it, but when i add it there appears 2 linking errors
Error LNK2038 mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2'
error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug'
i can't say for sure, but maybe thats msvc-only issue because i never was facing such problem in clang

Related

LNK 2038: RuntimeLibrary mismatch when using #include <xxx>

so I have C++ code in a dll 'MyDll', which is PInvoked by a C# project. This setup has been working well. Recently I introduced a few instances of #include <> and now, whenever I try to compile in Debug mode, I get the LNK 2038 error:
1>SimConnect.lib(SimConnectClient.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in MyDll.obj
1>SimConnect.lib(commClient.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in MyDll.obj
1>SimConnect.lib(client.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in MyDll.obj
SimConnect.lib is a release version (I don't have the source code) and there fore, it's RuntimeLibrary's value is MD (Multit-hreaded DLL (release)). Now, according to several answers on SO I've already found, I changed my RuntimeLibrary to MD in the Debug configuration.
My problem is concretely that, even after changing the RuntimeLibrary on MyDll's project's properties to Multi-threaded Dll (MD) in the Debug configuration, I still get the exact same errors. Since I am getting the exact same error, the key part being
"... doesn't match value 'MDd_DynamicDebug' in MyDll.obj"
even though the project properties have been changed, I take this as a hint that I am probably not changing the RuntimeLibrary's value correctly?
Furthermore, the errors only pop up when I use #include <> (#include "xxx" is not a problem"). Whenever I comment out any #include <> the errors don't trouble me.
Could someone give me a hint about what I might be doing wrong?
It would be also interesting to know why using these #includes trigger the mismatch errors with SimConnect.

How can I avoid problems of compile environment such as _MSC_VER mismatch error? [duplicate]

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

mismatch detected for CRT library

I'm facing the following error message:
libcpmt.lib(stdhndlr.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in libcpmtd.lib(xlock.obj)
libcpmt.lib(stdhndlr.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MTd_StaticDebug' in mtu.obj
I have been searching over the internet but found nothing about CRT libraries being mismatched.
I have tried to define following preprocessor definition: _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH however it did not resolved my issue.
I'm trying to compile a Debug configuration (Release is compiling fine).
Project runtime library is being set to:
Multi-threaded Debug (/MTd)
How can I link a debug version of libcpmt.lib?

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

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

How do I make a solution developed in Visual C++ 2010 work in Visual C++ 2012? [duplicate]

This question already has answers here:
Compiling a MFC app from Visual Studio 2010 to 2012 RC results in LNK2038
(4 answers)
Closed 9 years ago.
How can I make a .cpp solution developed in Visual C++ 2010 work in Visual C++ 2012, I get the error below everytime I try to build,
1>DinaPhysics-vc10-md-32-d.lib(smPrinter.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smEventGeneratorTrait.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smIntegralType.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smTypes.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smVec3rBase.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smVec3r.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smVec2rBase.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smVec2r.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smVec3dBase.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smVec3d.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smVec4r.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smVecTypes.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smMath.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smUtil.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smVec4rBase.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smVec2d.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smVec2dBase.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>DinaPhysics-vc10-md-32-d.lib(smVec4dBase.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in ShipDeckLandingExample.obj
1>..\..\..\Bin\VC10-32\Debug\ShipDeckLandingExample-vc10-md-32-d.exe : fatal error LNK1319: 18 mismatches detected
Thanks in advance..
If "Rebuild solution" doesn't fix it, it's possible that you are linking statically to a .lib that was created with a previous version of Visual Studio, and that also uses the Standard Template Library.
Quoting from MSDN here
•To implement various optimizations and debugging checks, the C++ Standard Library implementation intentionally breaks binary compatibility among versions of Visual Studio (2005, 2008, 2010, 2012). When the C++ Standard Library is used, this forbids the mixing of object files and static libraries that are compiled by using different versions into one binary (EXE or DLL), and forbids the passing of C++ Standard Library objects between binaries that are compiled by using different versions. The mixing of object files and static libraries (using the C++ Standard Library) that were compiled by using Visual C++ 2010 with those that were compiled by using Visual C++ in Visual Studio 2012 emits linker errors about _MSC_VER mismatch, where _MSC_VER is the macro that contains the compiler's major version (1700 for Visual C++ in Visual Studio 2012). This check cannot detect DLL mixing, and cannot detect mixing that involves Visual C++ 2008 or earlier.