.vscode下cmake编译配置
1.编写好程序的Makefile文件(这里就不细说了)
2.快捷键(Ctrl+Shift+p),输入task,选择 配置任务
3.随便选择一项,我这里选择的g++
4.以上会在.vscode文件夹下,生成一个tasks.json的配置文件,和默认配置
我修改好的 tasks.json 配置文件 (cmake)
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "CMakeBuild",
"type": "shell",
"command": "cmake ..",
"args": [],
"options": {
"cwd": "${workspaceFolder}/build"
}
},
{
"label": "build",
"type": "shell",
"dependsOn": ["CMakeBuild"],
"command": "make clean; make",
"options": {
"cwd": "${workspaceFolder}/build"
}
}
]
}或者
{
"version": "2.0.0",
"tasks": [
{
"label": "cmake",
"type": "shell",
"command": "cmake",
"args": ["../"],
"options": {
"cwd": "${workspaceFolder}/build"
}
},
{
"label": "make",
"type": "shell",
"command": "make",
"args": ["-j20"], //这里cmake -j20 表示 使用20核编译代码,可选项
"dependsOn": ["cmake"],
"options": {
"cwd": "${workspaceFolder}/build"
}
},
{
"label": "build",
"dependsOn": ["cmake","make"]
}
]
}
.vscode下cmake调试配置
1.点击运行,选择添加配置
2.选择C/C++: (gdb) 启动,会生成 launch.json 配置文件,和配置模版,修改launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", //配置名称,会在启动配置的下拉菜单中显示
"type": "cppdbg", //配置类型,只能为cppdbg
"request": "launch", //请求类型,可以为launch或attach
"program": "${workspaceFolder}/build/可执行程序文件名", //将要调试的程序的路径【执行程序名不要遗漏了】
"args": [], //调试时传递给程序的命令行参数
"stopAtEntry": false, //设为true程序会暂停在入口处
"cwd": "${workspaceFolder}/build", //调试程序时的工作目录
"environment": [], //环境变量
"externalConsole": false, //调试时是否显示控制台窗口
"MIMode": "gdb", //指定连接的调试器,可以为gdb或lldb
"miDebuggerPath": "/usr/bin/gdb", //gdb路径
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
,"preLaunchTask": "build" //调试开始前执行的任务,一般为编译过程,会调用tasks.json里面的任务,调试过程中没有代码改动的话可以注释掉
//,"preLaunchTask": "build" //调试过程中没有代码改动的话可以注释掉,像这样
}
]
}
参考:Windows使用VSCode远程Linux(ConteOS)开发/调试C/C++(超详细)_zy_workjob的专栏-CSDN博客