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

相关推荐
sphw5 小时前
nixnb: Jupyter Notebook 优雅分享
ide·人工智能·jupyter
NoteStream12 小时前
【c语言基础】C语言常见概念
c语言·开发语言·编辑器
布鲁飞丝18 小时前
从零实现富文本编辑器#-浏览器选区与编辑器选区模型同步
java·前端·编辑器
计算机内卷的N天18 小时前
CMake与Visual Studio的使用
c++·ide·visual studio
咱入行浅18 小时前
一款实用的 Visual Studio 发布部署插件,助力提高部署效率!
ide·visual studio
谢斯19 小时前
[vscode] 使用unity打开vscode的取消.csproj的显示
ide·vscode·unity
2501_916007471 天前
SwiftUI 声明式语法与 Xcode 预览功能详解
ide·vscode·ios·swiftui·个人开发·xcode·敏捷流程
呐抹倾1 天前
【译】Visual Studio 停用:针对旧版本 Visual Studio 的支持提醒
ide·visual studio
爱就是恒久忍耐2 天前
使用VSCode开发STM32 (通用版本)
ide·vscode·stm32
FlightYe2 天前
音视频修炼之视频基础(一):视频基础理论
android·c++·vscode·音视频·androidx·android runtime