c++msbuildvcpkgvcxproj

Why is my projects runtime library MD when I configured it to use MT?


I have a pretty large codebase and I use Vcpkg. I was previously using /MD, but there were just too many DLLs being produced by Vcpkg, so I decided to switch to /MT.

For some reason, every project except three are building with /MD, even though the project files clearly show MultiThreaded and MultiThreadedDebug are the only ones being used.

I’ve done clean rebuilds and manually deleted all obj and bin directories, but nothing seems to work.

Here is the dumpbin output for one of the libraries that keeps ending up as /MD:

File Type: LIBRARY

   Linker Directives
   -----------------
   /NODEFAULTLIB:LIBC.LIB
   /DEFAULTLIB:MSVCRT.LIB
   /NODEFAULTLIB:LIBCMT.LIB
   /NODEFAULTLIB:LIBCPMT.LIB
   /NODEFAULTLIB:LIBCP.LIB
   /DEFAULTLIB:MSVCPRT.LIB
   /FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0
   /alternatename:_Avx2WmemEnabled=_Avx2WmemEnabledWeakValue
   /FAILIFMISMATCH:_MSC_VER=1900
   /FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=0
   /FAILIFMISMATCH:RuntimeLibrary=MD_DynamicRelease
   /DEFAULTLIB:msvcprt
   /FAILIFMISMATCH:annotate_string=0
   /FAILIFMISMATCH:annotate_vector=0
   /include:??3@YAXPEAX@Z
   /DEFAULTLIB:uuid.lib
   /DEFAULTLIB:uuid.lib
   /DEFAULTLIB:uuid.lib
   /DEFAULTLIB:atls.lib
   /merge:ATL=.rdata
   /DEFAULTLIB:kernel32.lib
   /DEFAULTLIB:user32.lib
   /DEFAULTLIB:advapi32.lib
   /DEFAULTLIB:ole32.lib
   /DEFAULTLIB:shell32.lib
   /DEFAULTLIB:oleaut32.lib
   /DEFAULTLIB:uuid.lib
   /DEFAULTLIB:shlwapi.lib
   /DEFAULTLIB:shlwapi.lib
   /DEFAULTLIB:DbgHelp.Lib
   /include:?e@?$exception_ptr_static_exception_object@Ubad_alloc_@exception_detail@boost@@@exception_detail@boost@@2Vexception_ptr@3@B
   /include:?e@?$exception_ptr_static_exception_object@Ubad_exception_@exception_detail@boost@@@exception_detail@boost@@2Vexception_ptr@3@B
   /DEFAULTLIB:LIBCMT
   /DEFAULTLIB:OLDNAMES

  Summary

          50 .CRT$XCU
         17C .bss
        6200 .chks64
         200 .data
         3A4 .data$r
         508 .data$rs
      1076CC .debug$S
          50 .debug$T
         49C .drectve
        13E0 .pdata
        3DCF .rdata
        12F8 .rdata$r
         178 .text$di
       13797 .text$mn
         AD7 .text$x
         3AF .text$yd
          42 .voltbl
        250F .xdata
         454 .xdata$x
           8 ATL$__a
           8 ATL$__z

Here is the project for the library

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{BC9BB49D-3D4C-4EC4-876B-0582D381E3FC}</ProjectGuid>
    <RootNamespace>Base</RootNamespace>
    <Keyword>x64Proj</Keyword>
    <ApplicationEnvironment>title</ApplicationEnvironment>
    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>StaticLibrary</ConfigurationType>
    <PlatformToolset>v145</PlatformToolset>
    <UseOfAtl>false</UseOfAtl>
    <CharacterSet>MultiByte</CharacterSet>
    <WholeProgramOptimization>false</WholeProgramOptimization>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>StaticLibrary</ConfigurationType>
    <PlatformToolset>v145</PlatformToolset>
    <CharacterSet>MultiByte</CharacterSet>
    <WholeProgramOptimization>false</WholeProgramOptimization>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup>
    <_ProjectFileVersion>11.0.50727.1</_ProjectFileVersion>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <OutDir>bin\$(Configuration)\</OutDir>
    <IntDir>obj\$(Configuration)\</IntDir>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <OutDir>bin\$(Configuration)\</OutDir>
    <IntDir>obj\$(Configuration)\</IntDir>
  </PropertyGroup>
  <PropertyGroup Label="Vcpkg">
    <VcpkgEnableManifest>true</VcpkgEnableManifest>
    <VcpkgEnabled>true</VcpkgEnabled>
    <VcpkgUseStatic>true</VcpkgUseStatic>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <Optimization>Disabled</Optimization>
      <AdditionalIncludeDirectories>..\..\include;..\..\include\App;..\..\include\Rendering;..\Win;include;..\..\ThirdParty\sgCore;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <PreprocessorDefinitions>_DEBUG;_LIB;_WIN32_WINNT=0x0600;NTDDI_VERSION=0x06000100;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <MinimalRebuild>false</MinimalRebuild>
      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
      <FloatingPointModel>Fast</FloatingPointModel>
      <PrecompiledHeader />
      <WarningLevel>TurnOffAllWarnings</WarningLevel>
      <TreatWarningAsError>false</TreatWarningAsError>
      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
      <DisableSpecificWarnings>6011;6246;6285;6328;6334;6385;6386;6540;%(DisableSpecificWarnings)</DisableSpecificWarnings>
      <AdditionalOptions>/D "_SECURE_SCL=0" %(AdditionalOptions) /utf-8</AdditionalOptions>
      <EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
      <LanguageStandard Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">stdcpplatest</LanguageStandard>
      <MultiProcessorCompilation Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</MultiProcessorCompilation>
    </ClCompile>
    <ProjectReference>
      <LinkLibraryDependencies>true</LinkLibraryDependencies>
    </ProjectReference>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <AdditionalOptions>/D "_SECURE_SCL=0" %(AdditionalOptions) /utf-8</AdditionalOptions>
      <Optimization>MaxSpeed</Optimization>
      <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <OmitFramePointers>false</OmitFramePointers>
      <WholeProgramOptimization>false</WholeProgramOptimization>
      <AdditionalIncludeDirectories>..\..\include;..\..\include\App;..\..\include\Rendering;..\Win;include;..\..\ThirdParty\sgCore;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <PreprocessorDefinitions>NDEBUG;_LIB;_RELEASE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
      <BufferSecurityCheck>false</BufferSecurityCheck>
      <EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
      <FloatingPointModel>Fast</FloatingPointModel>
      <PrecompiledHeader>NotUsing</PrecompiledHeader>
      <WarningLevel>TurnOffAllWarnings</WarningLevel>
      <TreatWarningAsError>false</TreatWarningAsError>
      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
      <DisableSpecificWarnings>
      </DisableSpecificWarnings>
      <LanguageStandard Condition="'$(Configuration)|$(Platform)'=='Release|x64'">stdcpplatest</LanguageStandard>
      <MultiProcessorCompilation Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</MultiProcessorCompilation>
    </ClCompile>
    <ProjectReference>
      <LinkLibraryDependencies>true</LinkLibraryDependencies>
    </ProjectReference>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClCompile Include="CSGKernel.cpp" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="CSGKernel.h" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>

I am very confused where /MD is coming from because the project itself is set to /MT.



Solution

  • Okay after hours I noticed one of the projects have a header file which was forcing it to be MD

    #pragma comment(linker, "/NODEFAULTLIB:LIBC.LIB")
    #pragma comment(linker, "/DEFAULTLIB:MSVCRT.LIB")
    #pragma comment(linker, "/NODEFAULTLIB:LIBCMT.LIB")
    #pragma comment(linker, "/NODEFAULTLIB:LIBCPMT.LIB")
    #pragma comment(linker, "/NODEFAULTLIB:LIBCP.LIB")
    #pragma comment(linker, "/DEFAULTLIB:MSVCPRT.LIB")