PDA

View Full Version : LIBCMTD.lib and MSVCRTD.lib question



SirJonas
16th February 2017, 18:44
Hello sometimes when i add to my project my static compiler and dynamic compiler show me error's with LIBCMTD.lib and MSVCRTD.lib. Normally this can be solved including in the project the corresponding version you want to use for example i want to use static link libraries so when i create with only this. But sometimes when i select both in the project and select which i want to use show me these error's. Some way to obligate to my project to compile only in static or only dynamic using -MTd for static and -MD for Dynamic?
How will be something like:
CMAKE_XFLAGS_ ... I dont remember well how will be ? Thanks in advance!

d_stranz
17th February 2017, 17:53
I use -MD (Release mode) and -MDd (Debug mode). In Debug mode, I also set the Project -> Properties -> Linker -> Input -> Ignore Specific Default Libraries property to "MSVCRT;%(IgnoreSpecificDefaultLibraries)"

This eliminates the linking errors in Debug mode. For some strange reason this setting is not needed in Release mode. I don't have any idea how to do this in CMake. The linker command line in MSVC shows /NODEFAULTLIB:"MSVCRT", so maybe adding "-NODEFAULTLIB:'MSVCRT'" to your CMAKE_CXX_FLAGS variable will do this.

You most likely cannot do static linking to the MSVC runtime libraries if you are using Qt DLLs. These will also be linked to the MSVC runtime DLLs, and you can't mix dynamic and static links to MSVC runtime libraries in the same executable.

SirJonas
17th February 2017, 22:19
But the dynamic flags are (/MD and /MDd) and static flags are (/MT and /MTd).


MD -> Multi Threaded DLL.
MDd -> Multi Threaded Debug DLL . Like you said:
-MD (Release mode) and -MDd (Debug mode).
But normally it's for dynamic linking.

And for static linking is -MT or -MTd.


-MT -> Multi-Threaded
-MTd -> Multi-Threaded Debug . In other words, -MT (Release mode) and -MTd (Debug mode).

d_stranz
18th February 2017, 02:56
And so? This is the part you need to read:


You most likely cannot do static linking to the MSVC runtime libraries if you are using Qt DLLs. These will also be linked to the MSVC runtime DLLs, and you can't mix dynamic and static links to MSVC runtime libraries in the same executable.

Meaning, you cannot link statically to the MSVC runtime (using -MT or -MTd) if you are linking to Qt DLLs (which use -MD or -MDd). If your code is completely self-contained (i.e. doesn't use Qt or any other DLLs linked to the MSVC runtime) then you can link however you want.