ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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 put the below fields for in respective json files are present as those commands are the ones that pipes and enables the code with debugger in vscode and terminal.

In launch.json-- 1. "preLaunchTask": "prerun" 2. "avoidWindowsConsoleRedirection": true 3. "stopAtEntry": false

In tasks.json 1. In prerun task "command": "source ./devel/setup.bash && export ROS_MASTER_URI=http://localhost:11311/ " 2. In build task "command": "catkin config --extend /opt/ros/kinetic && catkin build -DCMAKE_BUILD_TYPE = Debug -j8"


***************** 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" } ] }

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 launch.json and tasks.json, tasks.json, I could debug my executables(the ones I run using roslaunch or rosrun from terminal) in vscode effortlessly.

Please note to put use the below fields for correctly in respective json files are present as those commands are the ones that pipes helps to pipe and enables enable the code with debugger in vscode and terminal.

In launch.json-- 1. *In launch.json--*

  1. "preLaunchTask": "prerun" 2. "prerun"
  2. "avoidWindowsConsoleRedirection": true 3. true
  3. "stopAtEntry": false

In tasks.json --

In tasks.json 1. In prerun task

  1. in Prerun task a. "command": "source ./devel/setup.bash && export ROS_MASTER_URI=http://localhost:11311/ " 2. "
  2. In build task 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"
         }
     ]
}

}