I installed ROS2 on the ubuntu 20.04 by apt install. I can run talker by root user, but can not run in the normal user:
root@ubuntu:~# ros2 run demo_nodes_cpp talker
[INFO] [1696303644.004298256] [talker]: Publishing: 'Hello World: 1'
[INFO] [1696303645.004122720] [talker]: Publishing: 'Hello World: 2'
[INFO] [1696303646.004077588] [talker]: Publishing: 'Hello World: 3'
if I switch to normal user:
$ ros2 run demo_nodes_cpp talker
/opt/ros/foxy/lib/demo_nodes_cpp/talker: error while loading shared libraries: librclcpp.so: cannot open shared object file: No such file or directory
And using locate command can find all of the dependency:
$ locate librclcpp.so
/opt/ros/foxy/lib/librclcpp.so
/opt/tros/lib/librclcpp.so
I just run "source /opt/ros/foxy/setup.bash" before using any ros2 command. Here is my LIB PATH:
$ echo $LD_LIBRARY_PATH
/opt/ros/foxy/opt/yaml_cpp_vendor/lib:/opt/ros/foxy/opt/rviz_ogre_vendor/lib:/opt/ros/foxy/lib/aarch64-linux-gnu:/opt/ros/foxy/lib
And the file permission:
$ ls -lh /opt/ros/foxy/lib/librclcpp.so
-rwxrwxrwx 1 root root 1.8M May 27 15:27 /opt/ros/foxy/lib/librclcpp.so
Is there anything missing?
There are 2 solutions for this:
You can add Library Path each time you run the node export LD_LIBRARY_PATH=/your_path:$LD_LIBRARY_PATH
In CmakeLists.txt add this line set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) If you add this you need not export the Path.