VSCode 使用CMakePreset找不到cl.exe编译器的问题

在用vscode开发c++项目的时候,使用预先配置的CMakePresets.json可以把一些特定的cmake选项固定下来,在配置时直接使用 "cmake --config --preset presetname"就可以进行配置,免去在命令行输入过多的配置参数。

但是在vscode中,经常会遇到找不到 cl.exe 的问题,这是因为cl.exe的全局访问需要配置一些环境变量,如果安装了VisualStudio之后,默认就会有一个类似 Developer Powershell for VS 2022 的程序,打开这个程序,就会进入一个powershell命令行,而且自动正确配置要使用cl.exe的环境变量。

同时,要vscode的CMakeTools在 Developer Powershell中运行config步骤,根据官方的提示,需要从 Developer Powershell中打开vscode。

If you're a windows developer, you must open Visual Studio Code from a developer command prompt. Or, run the CMake: Scan for Compilers command before the CMake Tools extension can detect build tools (CMake, Ninja) that are installed with Visual Studio.

 具体步骤如下:

1. 从开始菜单中打开developer powershell 或者 developer command prompt:

VSCode 使用CMakePreset找不到cl.exe编译器的问题_第1张图片

2. 在终端中进入项目的文件夹目录

3. 输入 "code ." 打开vscode

4. 然后选择需要配置的CMakePreset,进行配置即可。

你可能感兴趣的:(Windows,c++,vscode,ide,编辑器)