vscode c++ launch.json和 task.json

launch.json 

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/main",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Build",
        }
    ]
}

 task.json

{
	"version": "2.0.0",
	"options": {
		"cwd": "${workspaceFolder}/build"
	},
	"tasks": [
		{
			"type": "shell",
			"label": "cmake",
			"command": "cmake",
			"args": [
				".."
			]
		},
		{
			"label": "make",
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"command": "make",
			"args": []
		},
		{
			"label": "Build",
			"dependsOrder": "sequence",
			"dependsOn": [
				"cmake",
				"make"
			]
		}
	],
}
Visual Studio Code中配置C++launch.json文件,是配置调试任务的核心步骤,以下是相关信息: ### 配置前的准备 在VScode配置C/C++环境,需设置tasks.jsonlaunch.json文件,同时要安装C/C++扩展,还可配置c_cpp_properties.json文件,用于引入第三方库、指定头文件路径等 [^2]。 ### 最简配置示例 VS Code中的launch.json文件可对调试任务进行配置。以下是一个VS Code C++ launch.jsontask.json的最简配置示例: ```json { "version": "2.0.0", "tasks": [ { "type": "shell", "label": "C/C++: g++.exe build active file", "command": "E:\\MinGW\\mingw-w64\\mingw64\\bin\\g++.exe", // 修改自己的g++地址 "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "${workspaceFolder}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true } } ] } ``` 在这个示例中,`command`字段需修改为自己的g++地址,该配置可实现对活动文件的编译 [^4]。 ### 配置优势 在调试方面,VS Code巧妙地结合了Linux世界中C/C++调试主力军GDB(GNU Debugger)Windows平台以强大图形化界面著称的Visual Studio Debugger的优势,通过Debug Adapter Protocol(DAP) 提供了一个统一的调试接口 [^3]。 ### 配置意义 理解launch.json文件中最常用的配置字段,涵盖基本调试设置、程序控制、环境配置高级调试功能等,能帮助开发者高效配置调试环境,提升开发效率 [^1]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值