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

VSCode debug/launch ROS2 node, preLaunchTask does not source the environment

asked 2021-05-31 07:23:52 -0500

Markus Bader gravatar image

updated 2021-05-31 07:29:44 -0500

Hi

I like to use VSCode to debug my ROS2 project. But It looks like that the preLaunchTask is not working and ROS2 is not sourced. If I run my launch configuration I am getting the following errors on the Terminal and DEBUG CONSOLE. If I start vscode from an already source bash everything works, but I like to get it working without this workaround.

Terminal

/home/max/projects/car/ros2/dev_ws/install/cpp_pubsub/lib/cpp_pubsub/talker: error while loading shared libraries: librclcpp.so: cannot open shared object file: No such file or directory
[1] + Done                       "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-mbtt6mxm.ca9" 1>"/tmp/Microsoft-MIEngine-Out-6jm7uauf.vrr"

DEBUG CONSOLE

=thread-group-added,id="i1"
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
=cmd-param-changed,param="pagination",value="off"
Stopped due to shared library event (no libraries added or removed)
Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
[Inferior 1 (process 15947) exited with code 0177]
The program '/home/max/projects/car/ros2/dev_ws/install/cpp_pubsub/lib/cpp_pubsub/talker' has exited with code 177 (0x000000b1).

The following tasks.json and launch.json shows my configuration. Can some give me a hint?

Greeting Markus

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "prerun",
            "type": "shell",
            "command": ". install/setup.bash"
        }
    ]
}

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "talker",
            "type": "cppdbg",
            "request": "launch",
            "program": "/home/max/projects/car/ros2/dev_ws/install/cpp_pubsub/lib/cpp_pubsub/talker",
            "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
                }
            ]
        }
    ]
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-11-10 04:38:23 -0500

bvaningen gravatar image

My solution for this is to open a terminal, source the setup as normal (. install/setup.bash), and then run vscode through the terminal with code .

edit flag offensive delete link more

Question Tools

4 followers

Stats

Asked: 2021-05-31 07:23:52 -0500

Seen: 1,330 times

Last updated: Nov 10 '21