C++ LNK2038:检测到“RuntimeLibrary”不匹配:值“MT_StaticRelease”与 file.obj 中的值“MD_DynamicRelease”不匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28887001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in file.obj
提问by Ahmed Hassan
I am Integrating Matlab
, C
and Cuda
together in a project. I used Matlab mix in order to connect matlab mx function written in c with the cuda runtime library, a linking error appear about conflict in static release and dynamic release between the c file and the library. Can anyone solve this?
我正在整合Matlab
,C
并Cuda
一起在一个项目中。我使用Matlab mix为了将用c编写的matlab mx函数与cuda运行时库连接起来,出现关于c文件和库之间静态发布和动态发布冲突的链接错误。任何人都可以解决这个问题吗?
error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in file.obj.
回答by tux3
The library and your project must be linked with the same settings with regards to the C Runtime Library.
库和您的项目必须使用与 C 运行库相关的相同设置进行链接。
In your case one was linked against the CRT DLL (/MD) and the other was linked statically (/MT).
在您的情况下,一个链接到 CRT DLL (/MD),另一个链接静态 (/MT)。
You just need to make sure both match and this errorwill go away.
你只需要确保两者匹配,这个错误就会消失。
回答by Rahav
This error can occur when you are staticallylinking your project with a library (typically a file with .lib extension) but the linker setting in your Visual Studio project are set to dynamicallylink (meaning the link will occur during runtime, usually with a .dll file).
当您将项目与库(通常是具有 .lib 扩展名的文件)静态链接但 Visual Studio 项目中的链接器设置设置为动态链接时,可能会发生此错误(意味着链接将在运行时发生,通常带有.lib 扩展名)。 dll 文件)。
To define that you need the project to use static linking start Visual Studio. In the Solution Explorerpane, right click the project name, and select Properties. Expand the properties as shown in the figure below: C/C++ --> Code Generation --> Runtime Library, select the Multi-threaded (/MT)
option from the dropdown menu.
要定义您需要项目使用静态链接,请启动Visual Studio。在“解决方案资源管理器”窗格中,右键单击项目名称,然后选择“属性”。展开如下图所示的属性:C/C++ --> Code Generation --> Runtime Library,Multi-threaded (/MT)
从下拉菜单中选择选项。
回答by GWKit
for sharing purpose.
用于分享目的。
I'm using 2017 VS version which successfully open and run an old 2008 solution. Now, if for some reason, even if you change all your libraries and your main project to have the same runtime library param (under properties, see above posters) but you are still getting the same error message, try opening each individual .vcxproj file. Search under "RuntimeLibrary" and make their value same throughout all the vcxproj files. For some reason, these vcxproj files never update to the same value that I stated in the properties settings and I have to change them manually in the vcxproj.
我正在使用 2017 VS 版本,该版本成功打开并运行旧的 2008 解决方案。现在,如果出于某种原因,即使您将所有库和主项目更改为具有相同的运行时库参数(在属性下,请参阅上面的海报)但您仍然收到相同的错误消息,请尝试打开每个单独的 .vcxproj 文件. 在“RuntimeLibrary”下搜索并使它们在所有 vcxproj 文件中的值相同。出于某种原因,这些 vcxproj 文件永远不会更新为我在属性设置中声明的相同值,我必须在 vcxproj 中手动更改它们。
Optionally, if you wish, open vcproj files too and change their "RuntimeLibrary" to be the same as well. Here the value is in digit.
或者,如果您愿意,也可以打开 vcproj 文件并将它们的“RuntimeLibrary”更改为相同的。这里的值是数字。
回答by hoopyfrood
As others have mentioned the runtime library switch on cl.exe must match between all of the compiled modules. In MSBuild this is referenced as ClCompile>/RuntimeLibrary.
正如其他人提到的,cl.exe 上的运行时库开关必须在所有编译模块之间匹配。在 MSBuild 中,这被引用为 ClCompile>/RuntimeLibrary。
However, even if these match you might still encounter this problem if there is a "#undef DEBUG" or "#undef _DEBUG" somewhere in your project. The yvals.h header that is part of the VC++ runtime library headers can change what is compiled into your obj files if these macros are changed.
但是,即使这些匹配,如果您的项目中某处存在“#undef DEBUG”或“#undef _DEBUG”,您仍然可能会遇到此问题。如果更改了这些宏,则作为 VC++ 运行时库头文件一部分的 yvals.h 头文件可以更改编译到 obj 文件中的内容。
Use "dumpbin /all foo.obj >foo.txt" to check what is actually going into your obj files. Look for the header "Linker Directives" in that output.
使用“dumpbin /all foo.obj >foo.txt”来检查您的 obj 文件中实际包含的内容。在该输出中查找标题“链接器指令”。
回答by user889030
Here are proper steps to fix
以下是修复的正确步骤
Error 69 error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease'
this mean that runtime lib is staticaka lib( MT_StaticRelease) Which is different then you project value DynamicLib aka dll(MD_DynamicRelease)
这意味着运行时库是静态的又名lib( MT_StaticRelease) 这与您的项目值动态库又名dll( MD_DynamicRelease) 不同
- right click on solution
- click properties
- configuration properties -> General
- 右键单击解决方案
- 单击属性
- 配置属性 -> 常规
change Configuration Type to Static Lib (lib)from Dynamic Lib (dll)
将配置类型 从动态库 (dll)更改为静态库 (lib )
In case you have reverse scenario and the above steps not fix problem then play with this option
如果您有相反的情况并且上述步骤无法解决问题,请使用此选项
C/C++ --> Code Generation --> Runtime Library select Multi threaded
回答by Jonah Simon
This would work better as a comment to GWKit but I don't have the reputation for it. He mentions having to update the vcxproj files because they don't actually change. In my case they only saved after hitting "saveAll" and then closing visual studio. I got a prompt asking if i want to save changes to properties which were saved and after clicking yes the vcxproj files were properly updated.
作为对 GWKit 的评论,这会更有效,但我没有声誉。他提到必须更新 vcxproj 文件,因为它们实际上并没有改变。在我的情况下,他们只在点击“saveAll”然后关闭 Visual Studio 后才保存。我收到一个提示,询问我是否要保存对已保存属性的更改,单击“是”后,vcxproj 文件已正确更新。