安装 VS 2019 后 CMake 找不到 VS 2017 C++ 编译器
CMake does not find VS 2017 C++ compiler after installation of VS 2019
我安装了 Visual Studio 2017 Professional 以及 Visual Studio 2019 Professional。
由于一些项目限制我无法控制,不得不使用VS 2017 Compiler来编译代码。在安装 Visual Studio 2019 之前,以下 CMake 命令运行良好:
cmake -G "Visual Studio 15 2017 Win64"
但是安装VS 2019后,上面一行给出了如下错误:
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 systen cannot find the given file"。
谁能帮我解决这个问题?遗憾的是,到目前为止,我必须为这个特定项目使用 VS2017 的编译器。
编辑: 正如 Neil 在评论中所建议的那样,使用开发人员命令提示符效果很好。有什么方法可以使用 Windows 命令提示符吗?它只是更容易使用。
Edit2: 我现在使用 Neil 建议的解决方案和 运行 Visual Studio 命令提示符中所需的命令,因为我不知道如何在 Windows 命令提示符下正确执行。
CMake 始终尝试查找 Visual Studio 的最新版本。因此,如果安装了 VS2019 但未正确检测到,3.14 之前的旧版 CMake 可能会失败。
请注意,如果重新运行,您需要从构建目录中删除 CMakeCache.txt 和 CMakeFiles 文件夹。
如果您打算将 VS2019 与 CMake 一起使用,您需要使用 CMake 的体系结构选项 (-A
),因为没有 "Visual Studio 16 2019 Win64" 生成器,例如cmake -G "Visual Studio 16 2019" -A x64
用于 64 位构建或 cmake -G "Visual Studio 16 2019" -A Win32
用于 32 位构建。架构选项是在 CMake 3.0.2 中引入的,因此您也可以使用它来代替旧 Visual Studio 安装的特定生成器名称。
我安装了 Visual Studio 2017 Professional 以及 Visual Studio 2019 Professional。
由于一些项目限制我无法控制,不得不使用VS 2017 Compiler来编译代码。在安装 Visual Studio 2019 之前,以下 CMake 命令运行良好:
cmake -G "Visual Studio 15 2017 Win64"
但是安装VS 2019后,上面一行给出了如下错误:
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 systen cannot find the given file"。
谁能帮我解决这个问题?遗憾的是,到目前为止,我必须为这个特定项目使用 VS2017 的编译器。
编辑: 正如 Neil 在评论中所建议的那样,使用开发人员命令提示符效果很好。有什么方法可以使用 Windows 命令提示符吗?它只是更容易使用。
Edit2: 我现在使用 Neil 建议的解决方案和 运行 Visual Studio 命令提示符中所需的命令,因为我不知道如何在 Windows 命令提示符下正确执行。
CMake 始终尝试查找 Visual Studio 的最新版本。因此,如果安装了 VS2019 但未正确检测到,3.14 之前的旧版 CMake 可能会失败。
请注意,如果重新运行,您需要从构建目录中删除 CMakeCache.txt 和 CMakeFiles 文件夹。
如果您打算将 VS2019 与 CMake 一起使用,您需要使用 CMake 的体系结构选项 (-A
),因为没有 "Visual Studio 16 2019 Win64" 生成器,例如cmake -G "Visual Studio 16 2019" -A x64
用于 64 位构建或 cmake -G "Visual Studio 16 2019" -A Win32
用于 32 位构建。架构选项是在 CMake 3.0.2 中引入的,因此您也可以使用它来代替旧 Visual Studio 安装的特定生成器名称。