Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in file.obj

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?

error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in file.obj. 
like image 414
Ahmed Hassan Avatar asked Mar 05 '15 20:03

Ahmed Hassan


3 Answers

This error can occur when you are statically linking your project with a library (typically a file with .lib extension) but the linker setting in your Visual Studio project are set to dynamically link (meaning the link will occur during runtime, usually with a .dll file).

To define that you need the project to use static linking start Visual Studio. In the Solution Explorer pane, 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. enter image description here

like image 146
Rahav Avatar answered Nov 03 '22 15:11

Rahav


The library and your project must be linked with the same settings with regards to the C Runtime Library.

In your case one was linked against the CRT DLL (/MD) and the other was linked statically (/MT).

You just need to make sure both match and this error will go away.

like image 65
tux3 Avatar answered Nov 03 '22 15:11

tux3


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.

Optionally, if you wish, open vcproj files too and change their "RuntimeLibrary" to be the same as well. Here the value is in digit.

like image 5
GWKit Avatar answered Nov 03 '22 13:11

GWKit