---
title: "[UE4]boost lib连接错误：LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL'"
author: "aigo"
date: "2016-04-20T07:37:43Z"
tags: []
categories: ["开源软件"]
slug: "ue4-boost-lib-lnk2038-mismatch-detected-for-iterator-debug-level"
draft: false
lastmod: "2016-04-19T22:11:09Z"
id: 2292442
url: "https://aigo.iteye.com/blog/2292442"
---

UE4工程的debug模式链接boost的时候出现错误：

UE4  boost error LNK2038: mismatch detected for '\_ITERATOR\_DEBUG\_LEVEL': value '2' doesn't match value '0' in 

 

以下是UE4源码的注释，意思是说UE4编译器在编译debug版本的时候仍然会链接release版本的第三方库，因为UE4的编译器不支持在调试debug版本的第三方库。

 

*// By default we use the Release C++ Runtime (CRT), even when compiling Debug builds.  This is because the Debug C++*

*// Runtime isn't very useful when debugging Unreal Engine projects, and linking against the Debug CRT libraries forces*

*// our third party library dependencies to also be compiled using the Debug CRT (and often perform more slowly.)  Often*

*// it can be inconvenient to require a separate copy of the debug versions of third party static libraries simply*

*// so that you can debug your program's code.*

bDebugBuildsActuallyUseDebugCRT = false;

内容转自：[https://forums.unrealengine.com/showthread.php?63340-Building-engine-with-Debug-Runtime-library](https://forums.unrealengine.com/showthread.php?63340-Building-engine-with-Debug-Runtime-library)

 

**解决办法：**

最简单的方法就是在构建debug版本时候也去链接release版本的第三方库。

 

网上另外一张方法：

在**MyProject.Build.cs**文件的构造方法中添加配置：

```
BuildConfiguration.bDebugBuildsActuallyUseDebugCRT = true;
```

 这样貌似链接boost是可以了，但是又出现其他链接错误：

 error LNK2019: unresolved external symbol "\_\_declspec(dllimport) void \_\_cdecl std::\_Debug\_message(wchar\_t const \*,wchar\_t const \*,unsigned int)" (\_\_imp\_?\_Debug\_message@std@@YAXPEB\_W0I@Z) referenced in function "int \_\_cdecl std::\_Atomic\_compare\_exchange\_strong\_4(unsigned long volatile \*,unsigned long \*,unsigned long,enum std::memory\_order,enum std::memory\_order)" (?\_Atomic\_compare\_exchange\_strong\_4@std@@YAHPECKPEAKKW4memory\_order@1@2@Z)

 

查了一下，论坛上说如果要使用CRT，需要使用源码编译的UE4，因为目前版本对VS2015支持还不完善，有时间了再尝试下。

详情见：[https://answers.unrealengine.com/questions/294191/vs2015-linker-errors.html](https://answers.unrealengine.com/questions/294191/vs2015-linker-errors.html)