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:
  1. 在终端中进入项目的文件夹目录

  2. 输入 "code ." 打开vscode

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

相关推荐
乐之者v15 小时前
AI编程 -- codex添加代码,在intellij Idea中没有显示,如何处理?
java·ide·intellij-idea
Eric.Lee202117 小时前
vscode格式化代码
ide·vscode·编辑器·c++格式化
会笑的小熊18 小时前
VScode项目推送到git仓库
ide·git·vscode
SilentSamsara18 小时前
装饰器基础:从闭包到装饰器的自然演变
开发语言·前端·vscode·python·青少年编程·pycharm
【 STM32开发 】20 小时前
VSCode 安装图解
ide·vscode·编辑器
_ 川三西21 小时前
Anaconda安装后环境变量的添加
vscode·conda
CHINA红旗下1 天前
如何使用vscode开发STM32
ide·vscode·stm32
boonya1 天前
Idea CC GUI插件如何通过 CC Switch 工具将 Claude Code 的后端配置为 DeepSeek 的 v4-pro 模型?
java·ide·intellij-idea
IOT.FIVE.NO.11 天前
Codex、Claude Code、Cherry Studio 实测对比:CLI、桌面端怎么选?
ide·人工智能·编辑器·ai编程·ai写作·visual studio·vibecoding
远游客-蜡台1 天前
vscode使用claude code的一点记录
vscode·ai