Reputation: 3640
The MSDN documentation says that you need to use the Runtime version that correpsonds to the Platform Toolset version, hence it leads to UB otherwise.
I have a legacy project that was migrated to Visual Studio 2019, and has a <PlatformToolset>v142</PlatformToolset>
but <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
.
I know that there should be ToolsVersion="Current"
or ToolsVersion="16.0"
which is generated by CMake.
I get no warnings from Visual Studio when building the project, but I am concerned if specifing incompatible versions will lead to linking the wrong CRT version.
When I build with /MD
it seems that everything is ok:
Image has the following dependencies:
msi.dll
MSVCP140D.dll
VCRUNTIME140D.dll
VCRUNTIME140_1D.dll
ucrtbased.dll
KERNEL32.dll
But the legacy project uses /MT
and I can't determine which CRT is used from the dumpbin
output for .obj
file:
Linker Directives
-----------------
/FAILIFMISMATCH:_MSC_VER=1900
/FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=2
/FAILIFMISMATCH:RuntimeLibrary=MTd_StaticDebug
/DEFAULTLIB:libcpmtd
/FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0
/DEFAULTLIB:uuid.lib
/DEFAULTLIB:uuid.lib
/DEFAULTLIB:LIBCMTD
/DEFAULTLIB:OLDNAMES
Is ToolsVersion even meaningfull and can it lead to linking the wrong CRT version?
How can I inspect which version of Runtime is linked when compiled with /MT
?
From the page about binary compatibility:
You can mix binaries built by different versions of the v140, v141, v142, and v143 toolsets. However, you must link by using a toolset at least as recent as the most recent binary in your app. Here's an example: you can link an app compiled using any 2017 toolset (v141, versions 15.0 through 15.9) to a static library compiled using, say, Visual Studio 2019 version 16.2 (v142). You just have to link them by using a version 16.2 or later toolset. You can link a version 16.2 library to a version 16.4 app as long as you use a 16.4 or later toolset.
So my concern is about some libraries to be built with ToolsVersion="4.0"
, which will not be compatible with binaries build by versions v140
..v142
.
Hence the question: will anything bad happen if instead of version 15.0 with v141 PlatformToolset a 4.0 ToolsVersion is be used?
Upvotes: 0
Views: 692