I had the same issue where my simple c++ code projects built with cmake works perfectly fine but not the same c++ file in catkin workspace which uses catkin_make. I had the executable run with out the errors but doesn't stop at my break points to debug my code. Later with the following changes in the launch.json and tasks.json, I could debug my executables(the ones I run using roslaunch or rosrun from terminal) in vscode effortlessly.
Please note to use the below fields correctly in respective json files as those commands are the ones that helps to pipe and enable the code with debugger in vscode and terminal.
*In launch.json--*
- "preLaunchTask": "prerun"
- "avoidWindowsConsoleRedirection": true
- "stopAtEntry": false
In tasks.json --
- in Prerun task
a. "command": "source ./devel/setup.bash && export ROS_MASTER_URI=http://localhost:11311/ "
- In build task
a. "command": "catkin config --extend /opt/ros/kinetic && catkin build -DCMAKE_BUILD_TYPE = Debug -j8"
The above changes would hopefully work for anyone struggling with a similar issue. The changes are considered to work assuming the ROS environment is setup with the required extensions and catkin_make is executed without any errors.
************** launch.json ***************
{
// 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": "(gdb) launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/devel/lib/project_folder/executable_file",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "prerun",
"MIMode": "gdb",
"targetArchitecture": "x64",
"avoidWindowsConsoleRedirection": true,
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
***************** tasks.json ****************
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "prerun",
"type": "shell",
"command": "source ./devel/setup.bash && export ROS_MASTER_URI=http://localhost:11311/ "
},
{
"label": "build",
"type": "shell",
"command": "catkin config --extend /opt/ros/kinetic && catkin build -DCMAKE_BUILD_TYPE = Debug -j8",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "clean",
"type": "shell",
"command": "catkin clean --yes"
},
{
"label": "release",
"type": "shell",
"command": "sudo checkinstall --install=no catkin build -j4 --cmake--args -DCMAKE_BUILD_TYPE=Release"
}
]
}
Do you mean you type roslaunch/rosrun in the built-in terminal?
ofc not. debug screen -> play button (or pressing F5), then I select ROS -> roslaunch (or rosrun) -> my package -> launch file. and then it starts a new console.