Reputation: 598
I have Visual Studio 2017 Professional installed as well as Visual Studio 2019 Professional.
Because of some project restrictions I cannot control, I have to use the VS 2017 Compiler to compile the code. Before the installation of Visual Studio 2019 the following CMake command was just working fine:
cmake -G "Visual Studio 15 2017 Win64"
But after installation of VS 2019, above line gives the following error:
CMake Error at CMakeLists.txt:9 (project):
Failed to run MSBuild command:
MSBuild.exe
to get the value of VCTargetsPath:
Das System kann die angegebene Datei nicht finden
The last line means something like "The systen cannot find the given file".
Can anyone help me solve the problem? Sadly, as of now, I have to use the compiler from VS2017 for this particular project.
Edit: As suggested by Neil in the comments, using the Developer Command Prompt works just fine. Is there any way to use the Windows command prompt? It's just easier to use.
Edit2: I now use the solution suggested by Neil and run the commands needed in Visual Studio Command Prompt, as I could not figure out how to do it correctly in Windows command prompt.
Upvotes: 1
Views: 2816
Reputation: 6744
CMake always tries to find the most recent version of Visual Studio. Therefore older releases of CMake before 3.14 may fail if VS2019 is installed and not properly detected.
Please note that you need to delete CMakeCache.txt and CMakeFiles folder from your build directory if rerunning.
If you intend to use VS2019 with CMake you need to use the architecture option (-A
) of CMake as there is no "Visual Studio 16 2019 Win64" generator, e.g. cmake -G "Visual Studio 16 2019" -A x64
for a 64-bit build or cmake -G "Visual Studio 16 2019" -A Win32
for a 32-bit build. The architecture option was introduced in CMake 3.0.2, so you can use that instead of the specific generator name for older Visual Studio installations too.
Upvotes: 4