ubuntu18.04 下ros melodic vscode配置开发环境记录
首先准备可以用命令行编译通过的ros工作空间及其相应节点并配置好txt文件等。注意不要用vscode 下的create catikn package创建功能包,否则编译出来好像没有可执行文件或者可执行文件多了个.pc的后缀,可能我创建的时候有问题,但不管了,用命令行创建就好了。
vscode 插件选择如下 (第一个 ROS 0.6.6)
1)在ros工作空间下第一级目录下启动输入 启动scode.
code .
2)选择Terminal->configue default build Task打开task.json文件
task.json内容要配置为如下:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"command": "catkin_make -DCMAKE_BUILD_TYPE=Debug",
"problemMatcher": [
"$catkin-gcc"
],
"group": "build",
"label": "build",
"detail": "compiler : /usr/bin/g++"
},
]
}
c_cpp_properties.json
"cppStandard": "c++17"配置的正确与否直接决定C++ intelligence的代码自动补全功能是否有效
"includePath" 里面包含头文件路径
{
"configurations": [
{
"browse": {
"databaseFilename": "",
"limitSymbolsToIncludedHeaders": true
},
"includePath": [
"/opt/ros/melodic/include/**",
"/usr/include/**"
],
"name": "ROS",
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "c++17"
}
],
"version": 4
}
ctrl+shift+P: Task Run Build Task编译
调试:debug选项下create a launch.json file(c++ GDB 调试)注意创建launch.json file文件之后要检查下你之前配置的tasks.json文件有没有被ide修改了,修改了就改回来。
launch.json改为如下,主要制定两个:
"program" :自己工作空间下workspace/devel/lib/节点名/可执行文件
"preLaunchTask":要填成跟tasks.json文件中“label"标签一样的内容。其实直接把这个标签删除也可以。
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/devel/lib/myros/myros_node",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
后面在要调试的cpp文件里面打断点,在debug选项卡下点击run and Debug就可以开始调试了。