colcon / colcon-core

Command line tool to build sets of software packages
http://colcon.readthedocs.io
Apache License 2.0
103 stars 46 forks source link

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

Closed ipa-rwu closed 1 year ago

ipa-rwu commented 1 year ago

I also posed this question in answers.ros.org in case anybody has the same issue.

Here is the problem:

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!

cottsay commented 1 year ago

At first glance, this is probably due to the fact that the hooks installed by the debs in /opt/ros/<rosdistro> are generated by ament, and the hooks generated by colcon might be a little different. Clearly they aren't completely compatible if this sort of bug is popping up.

This isn't really a solution to this exact issue, but installing using colcon on top of the files installed by the debs probably isn't a good idea for reasons other than what you're experiencing here. This is the sort of scenario that overlay workspaces are designed for. You should install the packages to a different location and source that workspace's setup script, which should automatically chain to the /opt/ros/<distro> setup script as well as long as it had already been sourced when the new workspace was created.

ipa-rwu commented 1 year ago

Thanks for you answer! I will close the issue.