VS code 调试C C++
参考网址:
https://www.cnblogs.com/lidabo/p/5888997.html 在Linux中使用VS Code编译调试C++项目
https://www.jianshu.com/p/2700f2b93b14 2019 linux下vscode C++配置
https://www.cnblogs.com/dotnetcrazy/p/6661921.html 1.跨平台开发之~ VSCode开发第一个C程序
1、在vscode里面下载c/c++官方插件:
注意:C / C ++扩展不包括C ++编译器或调试器。您需要安装这些工具或使用计算机上已安装的工具。流行的C ++编译器是用于Windows的mingw-w64,用于macOS的XCode的 Clang 和用于Linux的GCC。确保您的编译器可执行文件位于您的平台路径中,以便扩展程序可以找到它。该扩展还支持Windows的Windows子系统。
C/C++ 为必装,提供C/C++支持
Code Runner 必装,提供编译后程序的运行环境
C/C++ Snippets 建议 提供一些常用的C/C++片段,如for(;;){},安装后写代码方便(tip.如果想要添加自己写的代码段可以点左下角齿轮->用户代码片段)
EPITECH C/C++ Headers 为C/C++文件添加头部(包括作者、创建和修改日期等),并为.h头文件添加防重复的宏
File Templates 文件模板,可以自己添加文件模板
GBKtoUTF8 GBK 编码文件转换为UTF-8
Include Autocomplete 头文件自动补全
One Dark Pro 一个好看的vscode主题
Easy C++ projects 提供一个简单的编译模式,开启后只要安装了C/C++扩展就可以直接编译运行,建议不用,因为不能自己配置参数
2. 新建测试文件test.c
#include <stdlib.h> #include <stdio.h> void test() { printf("this is my test!!!"); } int main() { printf("this is my test!!!"); return 0; }
3. F5 或者 点击debug
图标
4. 点击设置图片,出现 选择环境,选择 c++

5.生成launch.json
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) Attach", "type": "cppdbg", "request": "attach", "program": "${workspaceFolder}/a.out", "processId": "${command:pickProcess}", "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] }, { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/a.out", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
6.Ctrl+Shift+B,输入Task 选择Others 添加tasks.json
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "c++", "type": "shell", "command": "g++", "args": ["-g", "/home/hkjc/Desktop/projects/C/test.c"], "group": { "kind": "build", "isDefault": true } } ] }
7.Ctrl+Shift+B生成a.out, F5即可调试 !
/***************************************************多个文件编译******************************************************/
https://blog.csdn.net/qq_34347375/article/details/81137962
1. 打开设置找到 code-runner.executorMap
因为我们是通过makefile文件来进行编译链接源程序的,所以在这里更改如下:
"c": "cd $dir && make $fileNameWithoutExt && ./$fileNameWithoutExt && make clean",
"cpp": "cd $dir && make $fileNameWithoutExt && ./$fileNameWithoutExt && make clean",
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!