Mac下 vscode c/c++ 自动编译配置,macvscode
分享于 点击 47121 次 点评:215
Mac下 vscode c/c++ 自动编译配置,macvscode
本人mac版本10.12.5 ,vscode版本为 1.13
步骤很简单,添加好各种与c++有关的插件后,reload一次,重启vscode。
在helloworld.cpp所在文件夹下创建.vscode文件夹,在.vscode中创建2个文件:tasks.json , launch.json
接着是各个文件的内容:
tasks.json:(编译配置,也就是用cpp生成a.out的过程)
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "g++", //command 和 args 组合为编译c++命令,即 g++ -g xxx.cpp -o a.out
"isShellCommand": true,
"args": ["-g","${file}","-o","a.out"], //${file}代表着任意文件名,代替了helloworld.cpp
"showOutput": "always",
"problemMatcher": { //正则匹配,删除无用符号
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
launch.json:(调试配置,也就是运行a.out的过程)
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/a.out", //调试,也就是运行a.out文件
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
"preLaunchTask": "g++" //代表执行launch.json前先执行tasks.json中的g++指令
}
]
}
配置完之后,按f5就能对任意在工作目录下的cpp文件进行一键编译运行调试了
相关文章
- 暂无相关文章
用户点评