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,进行配置即可。

相关推荐
相思难忘成疾11 小时前
RHEL9 文件管理与 vi/vim 编辑操作实验
linux·编辑器·vim
进击的雷神11 小时前
Trae AI IDE 完全指南:从入门到精通
大数据·ide·人工智能·trae
北风toto12 小时前
IDEA模块名字和文件夹名字不一样的解决方式
java·ide·intellij-idea
im_AMBER12 小时前
万字长文:编辑器集成Vercel AI SDK
前端·人工智能·react.js·前端框架·编辑器
:12113 小时前
idea17创建tomcat项目(计网底层核心理解!)
java·ide·intellij-idea
猿小猴子13 小时前
主流 AI IDE 之一的 华为云码道「CodeArts」 介绍
ide·人工智能·ai·华为云
monsion1 天前
OpenCode 学习指南
人工智能·vscode·架构
非鱼䲆鱻䲜1 天前
vscode开发stm32添加新的头文件路径和包含源文件
ide·vscode·stm32·cmake·包含头文件·包含源文件
liurunlin8881 天前
Go环境搭建(vscode调试)
开发语言·vscode·golang
chushiyunen1 天前
pycharm注意力残差示例
ide·python·pycharm