"colcon build --merge-install" change the environment variable "LD_LIBRARY_PATH"

asked 2022-11-08 04:17:17 -0500

rwu gravatar image

updated 2022-11-08 04:20:40 -0500

After I run the command

colcon build --merge-install --install-base /opt/ros/$ROS_DISTRO

I found the environment variable "LD_LIBRARY_PATH" changed from /opt/ros/galactic/lib/x86_64-linux-gnu:/opt/ros/galactic/lib to /opt/ros/galactic/lib. And then it caused it cannot find libraries under /opt/ros/galactic/lib/x86_64-linux-gnu.

Here are steps you can reproduce this error:

  1. You can use docker image "public.ecr.aws/docker/library/ros:galactic"

  2. put demo_nodes_cpp in your "src" folder. This demo needs libconsole_bridge.so.1.0 which is under /opt/ros/galactic/lib/x86_64-linux-gnu

  3. run colcon build --merge-install --install-base "/opt/ros/galactic"

  4. check the environment variable "LD_LIBRARY_PATH": echo $LD_LIBRARY_PATH. You should get /opt/ros/galactic/opt/yaml_cpp_vendor/lib:/opt/ros/galactic/lib/x86_64-linux-gnu:/opt/ros/galactic/lib
  5. save this container as a docker image. You can run docker ps to find this container ID. Then run ``` docker commit "container ID" "image name"
  6. start a container of the new docker image. Then check check the environment variable "LD_LIBRARY_PATH": echo $LD_LIBRARY_PATH `` You should get/opt/ros/galactic/lib`
  7. Run the demo ros2 run demo_nodes_cpp talker. You will get the error /opt/ros/galactic/lib/demo_nodes_cpp/talker: error while loading shared libraries: libconsole_bridge.so.1.0: cannot open shared object file: No such file or directory

There is no issue if only using colcon build. So I suspect the cause of this is from --merge-install.

Thank you for your help!

edit retag flag offensive close merge delete