athackst / vscode_ros2_workspace

A template for using VSCode as an IDE for ROS2 development.
https://althack.dev/vscode_ros2_workspace
Apache License 2.0
857 stars 177 forks source link

Question: how to source setup.bash before press F5 launch launch.json #46

Closed oridong closed 1 year ago

oridong commented 1 year ago

how to source setup.bash before press F5 launch launch.json ? the shell where gdb running must has the foxy environment variables, otherwise

error while loading shared libraries: librclcpp.so: cannot open shared object file: No such file or directory

athackst commented 1 year ago

Are you using the provided dockerfile or did you roll your own?

athackst commented 1 year ago

I think you have 2 options here:

  1. Either the shell environment has the appropriate environment variables set up
  2. You add a pre-launch task to source setup.bash

launch.json

    // Example gdb launch of a ros executable
    {
      "name": "(gdb) Launch (merge-install)",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/install/lib/${input:package}/${input:program}",
      "args": [],
      "preLaunchTask": "source",
      "stopAtEntry": true,
      "cwd": "${workspaceFolder}",
      "externalConsole": false,
      "MIMode": "gdb",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    },

tasks.json

        {
            "label": "source",
            "detail": "Source the directory",
            "type": "shell",
            "command": "source install/setup.bash", // path to your setup.bash file
            "problemMatcher": []
        }