Link Error LNK2038: RuntimeLibrary And _ITERATOR_DEBUG_LEVEL Mismatch

本文介绍了解决Visual Studio 2012中使用VC11编译器编译C++代码时遇到的LNK2038链接错误的方法。此错误通常发生在链接第三方库的发布版本时。文章提供了详细的背景信息,并给出了一种快速修复方案,通过设置特定的宏来禁用版本检查。
摘要由CSDN通过智能技术生成

转载自: 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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值