Help with Visual Studio Generator

I have a CMake project that works fine on Linux and which I am now porting to Windows, where I want to build from the command line using the Visual Studio C++ tools.

I initially used the Ninja generator on Windows but got this recurring error:

mt.exe : general error c101008d: Failed to write the updated manifest to the resource of file "myProj.exe". The system cannot open the device or file specified.

I think that error may be to do with multiple concurrent accesses of the manifest file so I am now using the Visual Studio generator instead as follows:

cmake -G "Visual Studio 15 2017" -A x64 -DPROJECT_VARIANT=MyVariant..\\..
cmake --build .

Is this a good method?

My CMakeLists.txt contains:

cmake_minimum_required(VERSION 3.12.0 FATAL_ERROR)

     STRING "Choose the type of build.")
message(STATUS "Build type is '${CMAKE_BUILD_TYPE}'")

project(myProj LANGUAGES CXX C)

On Linux, this builds a Release build, by default, and the executable is in the root of the current directory. On Windows it builds a Debug build by default, in directory Debug/myProj.exe.

Why does it build in Debug mode when I have specified a default build type of Release?

How would I force it to build Release in the cmake command?

Because CMAKE_BUILD_TYPE is ignored in case of generators supporting multiple configurations.

To control the build type in multi-config, use option --config of cmake:

cmake --build . --config Release

Thanks for your help. Your suggestion worked for my x64 build, but I need to build one variant as an x86 target (because it uses a vendor’s x86 library) so I specified:

cmake -G "Visual Studio 15 2017" -A x86 -DPROJECT_VARIANT=MyVariant ..\\..

but that resulted in:

Failed to run MSBuild command:

    C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/MSBuild/15.0/Bin/MSBuild.exe

So I guess that ‘-A’ specifies the build tools architecture to use rather than the target architecture?

How would I specify the target architecture please?

It’s -A Win32 for x86 builds. See CMake documentation for Visual Studio 15 2017 here

1 Like

All working now. Thank you!

With the VS generator (certainly for 2019) you can force ONLY one of the debug or release configurations to be added to the vcxproj file being output but using:


You can then pass a variable in from your command line “-DmyVariant=Debug” and check it with

if (DEFINED myVariant AND ${myVariant} STREQUAL “Debug”)

Hope that helps, you can generate in VS and see just that one config in the build configurations list then, so should be fine when just passing it onto msbuild too.