当前位置: 首页 > news >正文

详细介绍:WIN11+VSCODE搭建c/c++开发环境

搭建c/c++by win11+vscode

前面试过了ubuntu手到擒来的,没想到颇有些周折。可能解决方案也并不完美,先记录下来,以后有改进再来修改。就是+vscode,macos+vscode,win11+visual studio搭建,本来以为win11+vscode

UCRT64(推荐,兼容性更好)

MINGW64(传统 MinGW-w64)

CLANG64(LLVM Clang 版本)

方法 1:安装 UCRT64 版本的 GCC(推荐)
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
按回车选择默认安装(全部包)。
方法 2:安装 MINGW64 版本的 GCC(传统 MinGW-w64)
pacman -S --needed base-devel mingw-w64-x86_64-toolchain
方法 3:安装 CLANG64 版本的 GCC(LLVM Clang)
pacman -S --needed base-devel mingw-w64-clang-x86_64-toolchain

UCRT64: C:\msys64\ucrt64\bin

MINGW64: C:\msys64\mingw64\bin

CLANG64: C:\msys64\clang64\bin
添加环境变量
打开系统环境变量设置:

Win + S 搜索 “编辑框架环境变量” → “环境变量”。

修改 PATH:

在 “系统变量” 中找到 Path,点击 “编辑” → “新建”。

添加你的 MinGW-w64 的 bin 目录(例如 C:\msys64\ucrt64\bin)。

设置:

Compiler path: C:\msys64\ucrt64\bin\g++.exe(根据你的安装路径调整)。

IntelliSense mode: gcc-x64。
修改 tasks.json(编译配置)
按 Ctrl+Shift+P → Tasks: Configure Task → C/C++: g++.exe build active file,修改 args:
{
“version”: “2.0.0”,
“tasks”: [
{
“type”: “cppbuild”,
“label”: “C/C++: g++.exe build active file”,
“command”: “C:\msys64\ucrt64\bin\g++.exe”,
“args”: [
“-fdiagnostics-color=always”,
“-g”,
f i l e " , " − o " , " {file}", "-o", "file","o","{fileDirname}\KaTeX parse error: Expected '}', got 'EOF' at end of input: … "cwd": "{fileDirname}”
},
“problemMatcher”: ["$gcc"],
“group”: {
“kind”: “build”,
“isDefault”: true
},
“detail”: “Generated task by VS Code”
}
]
}

修改 launch.json(调试部署)
按 Ctrl+Shift+D → create a launch.json file → C++ (GDB/LLDB),修改:

{
“version”: “0.2.0”,
“configurations”: [
{
“name”: “g++.exe - Build and debug active file”,
“type”: “cppdbg”,
“request”: “launch”,
“program”: “${fileDirname}\f i l e B a s e n a m e N o E x t e n s i o n . e x e " , " a r g s " : [ ] , " s t o p A t E n t r y " : f a l s e , " c w d " : " {fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "fileBasenameNoExtension.exe","args":[],"stopAtEntry":false,"cwd":"{fileDirname}”,
“environment”: [],
“externalConsole”: false,
“MIMode”: “gdb”,
“miDebuggerPath”: “C:\msys64\ucrt64\bin\gdb.exe”,
“setupCommands”: [
{
“description”: “Enable pretty-printing for gdb”,
“text”: “-enable-pretty-printing”,
“ignoreFailures”: true
}
],
“preLaunchTask”: “C/C++: g++.exe build active file”
}
]
}
编译运行:

按 Ctrl+Shift+B 编译。

按 F5 调试运行。
总结:以上是配置c++文件,如果是c文件,修改json中的g++为gcc即可。
遇到的问题及解决:
1、调用外部终端输出: “externalConsole”: false,
这个false改为true后,运行和调试终端会闪退,我的解除是加入getchar()语句。scanf函数语句要加,return 0处也要加。
在这里插入图片描述
2、程序中具备中文运行输出乱码:
:就是这是因为vscode编码为utf-8,windows终端编码默认为GBK,我的解决方案

http://www.jsqmd.com/news/9177/

相关文章:

  • 笔记:寻找适合自己的简历工具(YAMLResume)
  • 实用指南:Linux 权限管理入门:从基础到实践
  • 用Google的DeepResearch+音频生成功能生成自己感兴趣内容的Podcast
  • Windows 11 24H2 中文版、英文版 (x64、ARM64) 下载 (2025 年 9 月发布)
  • Windows 11 25H2 正式版发布,新增功能简介
  • 快速浏览
  • Marchenko理论
  • 无法定时发送
  • 计算能力的重要性:从内存配置到进程迁移的未来展望
  • MongoDB财报超预期,文档数据库技术解析
  • 深入解析:【RabbitMQ】- Channel和Delivery Tag机制
  • 实用指南:vulkan游戏引擎renderer_frontend实现
  • 2020CSPS T1 儒略日题解
  • 调用百度AI接口实现网络图片中的文字识别
  • Golang|分布式搜索引擎中所使用到的设计模式 - 实践
  • Python 语言编程技巧
  • kafka 常用知识点 - 指南
  • 英语_阅读_ChatGPT_待读
  • QT开发技术【ffmpeg + QAudioOutput】音乐播放器 - 指南
  • 进程工具类 - C#小函数类推荐
  • 实用指南:React 组件异常捕获机制详解
  • win11 为什么我的程序断网就转入导后台进程
  • 深入解析:AI与区块链:数据确权与模型共享的未来
  • 10.6阅读笔记
  • 详细介绍:Qwen2.5-VL 损失函数
  • hetao 国庆
  • 详细介绍:AI健康小屋+微高压氧舱:科技如何重构我们的健康防线?
  • 详细介绍:运维 pgsql 安装完后某次启动不了
  • visual studio
  • [MCP] StreamableHTTPServer