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

相关推荐
2501_938790072 分钟前
从 0 到 1:解决 VsCode 远程连服务器后 Github Copilot 无法使用问题
服务器·vscode·github
君以思为故2 小时前
认识linux -- 编辑器vim以及编译器gcc/g++和Makefile文件
linux·编辑器·vim
数据饕餮2 小时前
faster-whisper热词详解与程序设计
ide·macos·xcode
歪歪1003 小时前
在C#中除了按属性排序,集合可视化器还有哪些辅助筛选的方法?
开发语言·前端·ide·c#·visual studio
尤超宇4 小时前
U-net 系列算法知识解读
编辑器
许泽宇的技术分享5 小时前
把 CLI 搬上 Web:在内网打造“可二开”的 AI IDE,为什么这条路更现实?
前端·ide·人工智能
2501_938791225 小时前
VsCode 远程模式 + 服务器:Github Copilot 安装后无法触发?原因解析
服务器·vscode·github
Eiceblue6 小时前
使用 Python 向 PDF 添加附件与附件注释
linux·开发语言·vscode·python·pdf
王RuaRua6 小时前
VScode C/C++环境配置
c语言·c++·vscode
宁雨桥7 小时前
VSCode插件开发实战:从零到发布的技术大纲
ide·vscode·编辑器