1. Problem Description
The problem happens when I was trying to compile C++ code base in Windows with VC11 compiler (Visual Studio Premier 2012). Linker Error LNK2038 pops up under debug version when linking against the release version of the third party libraries. (Bear in mind that the release version is compiled fine and running all the tests passed.)
Read through what LNK2038 is from Microsoft,
Linker Tools Error LNK2038. There are four types mismatching that are checked, _MSC_VER, _ITERATOR_DEBUG_LEVEL, RuntimeLibrary and _PPLTASKS_WITH_WINRT. Generally I believe that this is a good idea to enforce all the software are compiled with the same setting. But this should make an exception when involving the third party software that are not guaranteed to be compiled with the same settings.
Indeed as some of threads in Stackoverfolow, for example
_ITERATOR_DEBUG_LEVEL Mismatch and
RuntimeLibrary Mismatch, indicate that the proper fix is to setting the _ITERATOR_DEBUG_LEVEL and RuntimeLibrary as the same value across all the software including the third party libraries and DLL. And above two threads in Stackoverflow have also pointed out how to set them under Visual Stuido 2012.
2. Quick Fix
In case that the debug version of third party libraries or DLL are not available (in most case NOT, who will release debug version and debug version usually only useful for internal debugging or fixing technical issues which may be reported by customers). And as well in case that the C++ code base is compiled cross-platform via an invoking script, like make build debug, make build release, the following is helpful for you to cross this linking error hurdle. (For those compiling C++ code via Visual Studio IDE then set these variables via project configuration for C++ section.)
Using the following compiler options,
*
-D_ALLOW_MSC_VER_MISMATCH
This flag allows _MSV_VER mismatch
*
-D_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH
This flag allows _ITERATOR_DEBUG_LEVEL mismatch
*
-D_ALLOW_RUNTIME_LIBRARY_MISMATCH
This flag allows RuntimeLibrary mismatch
When -D appears in the VC compiler, it is to define the following as a MACRO before the actual compiling process starts (in this case before preprocessing starts). Now add these options into your compiler, then your software should fly.
These three MACROs are simply to turn off the mismatch detection for each variable respectively. Check the file, yvas.h, under your Visual Studio installation for more details.
Link Error LNK2038: RuntimeLibrary And _ITERATOR_DEBUG_LEVEL Mismatch
最新推荐文章于 2023-04-01 08:25:40 发布
本文介绍了解决Visual Studio 2012中使用VC11编译器编译C++代码时遇到的LNK2038链接错误的方法。此错误通常发生在链接第三方库的发布版本时。文章提供了详细的背景信息,并给出了一种快速修复方案,通过设置特定的宏来禁用版本检查。
摘要由CSDN通过智能技术生成