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

相关推荐
hallo1284 小时前
vscode环境迁移
ide·vscode·编辑器
家有狸花5 小时前
VSCODE驯服日记(三):配置C++环境
c++·ide·vscode
yufei-coder7 小时前
掌握 C# 中的 LINQ(语言集成查询)
windows·vscode·c#·visual studio
陈苏同学9 小时前
4. 将pycharm本地项目同步到(Linux)服务器上——深度学习·科研实践·从0到1
linux·服务器·ide·人工智能·python·深度学习·pycharm
怪我冷i9 小时前
使用vscode调试wails项目(golang桌面GUI)
vscode·golang
惜.己18 小时前
javaScript基础(8个案例+代码+效果图)
开发语言·前端·javascript·vscode·css3·html5
XiaoLiuLB19 小时前
ChatGPT Canvas:交互式对话编辑器
人工智能·自然语言处理·chatgpt·编辑器·aigc
菜鸟一皓20 小时前
IDEA的lombok插件不生效了?!!
java·ide·intellij-idea
satan–021 小时前
R语言的下载、安装及环境配置(Rstudio&VSCode)
开发语言·windows·vscode·r语言
五花肉村长1 天前
数据结构-队列
c语言·开发语言·数据结构·算法·visualstudio·编辑器