下载vscode的deb文件,使用sudo dpkg -i进行安装。 在命令行里输入code启动vscode。 在vscode的Extensions里安装C/C++扩展。
使用快捷键Ctrl+Shift+P,输入C/C++:Edit Configuration 范例如下:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/apollo_workspace/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-arm64"
}
],
"version": 4
}
如果需要增加包含目录,在includePath里进行增加。
在Terminal下选择Configure Tasks...进行配置 范例如下:
{
"version": "2.0.0",
"tasks": [
{
"label": "qmake (Debug)",
"type": "shell",
"command": "qmake",
"args": [
"${workspaceFolder}/apollocontroller_shenlanfd.pro",
"CONFIG+=debug" //
],
"problemMatcher": ["$gcc"],
"group": "build"
},
{
"label": "make (Debug)",
"type": "shell",
"command": "make",
"args": ["-j4"], //
"dependsOn": ["qmake (Debug)"],
"problemMatcher": ["$gcc"],
"group": "build"
}
]
}
编译时使用Ctrl+Shift+B进行编译。第一次先选qmake,再选make,后面只是.pro文件有变化时使用qmake,其它都make。范例中的apollocontroller_shenlanfd.pro改成当前工程的pro名称。
点击左侧的Run and Debug或者Ctrl+Shift+D配置调试文件。 范例如下:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Qt (GDB)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/apollocontroller_shenlanfd", //
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{"name": "LD_LIBRARY_PATH", "value": "/usr/local/qt5/lib"} //
],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Print",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
program根据实际项目名称进行修改。