Mac/Ubuntu20.04中vscode的c++配置文件
问题: “/usr/bin/gdb” --interpreter=mi --tty=${DbgTerm} 0<“/tmp/Microsoft-MIEngine-In-j0jw3ysj.z30” 1>"/tmp/Microsoft-MIEngine-Out
一、MAC
1、launch.json文件
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/${fileBasenameNoExtension}",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "Build with Clang"
}
]
}
2、tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Build with Clang",
"type": "shell",
"command": "clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"${file}",
"-o",
"${fileBasenameNoExtension}"
],
"group": "build"
},
{
"type": "cppbuild",
"label": "C/C++: g++ 生成活动文件",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
]
}
二、Ubuntu
1、launch.json
{
"configurations": [
{
// 这个调试任务的名字
"name": "C/C++: g++ build and debug active file",
// 调试任务的类型,它是由C/C++ extension定义的
"type": "cppdbg",
"request": "launch",
// 被调试的程序的路径
"program": "${fileDirname}/${fileBasenameNoExtension}",
// 被调试的程序的参数,这里我们的程序没有参数,故为空
"args": [],
// 是否则main函数设置断点
"stopAtEntry": false,
// 当前工作目录,current working directory
"cwd": "${fileDirname}",
// 环境变量
"environment": [],
// 是否使用
"externalConsole": false,
// 调试器,只能是gdb或者lldb
"MIMode": "gdb",
// gdb或者lldb的配置参数
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
// 前置依赖的任务,就是tasks.json里面的任务名字
"preLaunchTask": "C/C++: g++ build active file",
// debug工具的路径
"miDebuggerPath": "/usr/bin/gdb",
"miDebuggerArgs": "-q -ex quit; wait() { fg >/dev/null; }; /bin/gdb -q --interpreter=mi"
}
],
"version": "2.0.0"
}
2、tasks.json
{
"tasks": [
{
"type": "cppbuild",
// 任务的名称,类比makefile里面的target
// launch文件可以用这个名字来配置依赖,类比makefile里面的prerequisites
"label": "C/C++: g++ build active file",
// 编译器的路径,这里是g++
"command": "/usr/bin/g++",
// 编译器的参数,会被传给g++
// 当我们的代码依赖额外的库或者头文件时,通过这个配置来添加
"args": [
"-fdiagnostics-color=always",
"-g",
// ${file}为当前打开的文件,比如helloworld.cpp
// 当我们将其改为*.cpp时,它会编译所有cpp文件
"${file}",
"-o",
// ${fileDirname}为当前打开的文件所在的文件夹
// fileBasenameNoExtension为当前打开的文件名(没有扩展名),比如helloworld
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}" // current working directory被设为当前文件的文件夹
},
// problemMatcher会分析任务运行结果,然后将其中出现的错误或者警告,显示在问题面板中。
"problemMatcher": [
"$gcc"
],
// 任务分组,将当前任务分到build组,可以通过在Command Palette
// 输入run build task来运行build组的任务
// 当然,如果任务分组是test,可以用run test task来运行
"group": {
"kind": "build",
"isDefault": true
},
// 任务细节,可以自己修改
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
3、c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
总结
1.Mac中配置参考:
https://www.cnblogs.com/hzb462606/p/14605765.html
2.ubuntu中配置参考:
https://zhuanlan.zhihu.com/p/626527410?utm_id=0
注:原文中launch.json文件下,“stopAtEntry”: true,会自动在main函数处打断点,使程序在main处暂停。改为false即可。
添加:“miDebuggerArgs”: “-q -ex quit; wait() { fg >/dev/null; }; /bin/gdb -q --interpreter=mi”,避免终端出现多余内容。