Link Error LNK2038: RuntimeLibrary And _ITERATOR_DEBUG_LEVEL Mismatch

来源:互联网 发布:微信群控软件下载 编辑:程序博客网 时间:2024/05/16 14:03

转载自: http://cpluspluslearning-petert.blogspot.jp/2016/02/link-error-lnk2038-runtimelibrary-and.html

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.
阅读全文
0 0
原创粉丝点击