ros-tooling / cross_compile

A tool to build ROS and ROS2 workspaces for various targets
Apache License 2.0
187 stars 59 forks source link

Failed to find library 'rmw_dds_common__rosidl_typesupport_fastrtps_cpp' #363

Closed pojiro closed 2 years ago

pojiro commented 2 years ago

Description

NOTE: I confirmed below on rpi4 Ubuntu focal too.


I crosscompiled ros2 foxy for rpi4, aarch64, buildroot linux, successfully. And I copied generated artifacts to target's /usr/lib and /usr/include, both of the pathes are recognized. Then I ran my binary(so) from erlang vm which uses rcl and got Failed to find library 'rmw_dds_common__rosidl_typesupport_fastrtps_cpp' log.

I confirmed below,

iex(15)> cmd "ldd /usr/lib/librmw_dds_common__rosidl_typesupport_fastrtps_c.so"
ldd: $warning: you do not have execution permission for `/usr/lib/librmw_dds_common__rosidl_typesupport_fastrtps_c.so'
        linux-vdso.so.1 (0x0000007fb1a56000)
        librosidl_typesupport_fastrtps_c.so => /usr/lib64/librosidl_typesupport_fastrtps_c.so (0x0000007fb19e0000)
        librmw_dds_common__rosidl_generator_c.so => /usr/lib64/librmw_dds_common__rosidl_generator_c.so (0x0000007fb19c0000)
        librosidl_runtime_c.so => /usr/lib64/librosidl_runtime_c.so (0x0000007fb19a0000)
        libfastcdr.so.1 => /usr/lib64/libfastcdr.so.1 (0x0000007fb1970000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x0000007fb17b0000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000007fb1780000)
        libc.so.6 => /lib64/libc.so.6 (0x0000007fb15e0000)
        /lib/ld-linux-aarch64.so.1 (0x0000007fb1a1e000)
        librcutils.so => /usr/lib64/librcutils.so (0x0000007fb15b0000)
        libm.so.6 => /lib64/libm.so.6 (0x0000007fb1510000)
        libdl.so.2 => /lib64/libdl.so.2 (0x0000007fb14f0000)
iex(17)> cmd "ldd /usr/lib/librmw_fastrtps_cpp.so"
ldd: $warning: you do not have execution permission for `/usr/lib/librmw_fastrtps_cpp.so'
        linux-vdso.so.1 (0x0000007f97937000)
        librosidl_typesupport_fastrtps_c.so => /usr/lib64/librosidl_typesupport_fastrtps_c.so (0x0000007f97840000)
        librosidl_typesupport_fastrtps_cpp.so => /usr/lib64/librosidl_typesupport_fastrtps_cpp.so (0x0000007f97820000)
        librmw_fastrtps_shared_cpp.so => /usr/lib64/librmw_fastrtps_shared_cpp.so (0x0000007f97740000)
        libfastrtps.so.2 => /usr/lib64/libfastrtps.so.2 (0x0000007f96fd0000)
        libfastcdr.so.1 => /usr/lib64/libfastcdr.so.1 (0x0000007f96fa0000)
        librmw_dds_common__rosidl_typesupport_cpp.so => /usr/lib64/librmw_dds_common__rosidl_typesupport_cpp.so (0x0000007f96f80000)
        librmw_dds_common.so => /usr/lib64/librmw_dds_common.so (0x0000007f96f10000)
        librmw.so => /usr/lib64/librmw.so (0x0000007f96ef0000)
        librosidl_runtime_c.so => /usr/lib64/librosidl_runtime_c.so (0x0000007f96ed0000)
        librcutils.so => /usr/lib64/librcutils.so (0x0000007f96ea0000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x0000007f96ce0000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000007f96cb0000)
        libc.so.6 => /lib64/libc.so.6 (0x0000007f96b10000)
        /lib/ld-linux-aarch64.so.1 (0x0000007f978ff000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x0000007f96af0000)
        libdl.so.2 => /lib64/libdl.so.2 (0x0000007f96ad0000)
        libtinyxml2.so.6 => /usr/lib64/libtinyxml2.so.6 (0x0000007f96aa0000)
        libssl.so.1.1 => /usr/lib64/libssl.so.1.1 (0x0000007f96a00000)
        libcrypto.so.1.1 => /usr/lib64/libcrypto.so.1.1 (0x0000007f96750000)
        librt.so.1 => /lib64/librt.so.1 (0x0000007f96730000)
        libm.so.6 => /lib64/libm.so.6 (0x0000007f96690000)
        librosidl_typesupport_cpp.so => /usr/lib64/librosidl_typesupport_cpp.so (0x0000007f96670000)
        libatomic.so.1 => /lib64/libatomic.so.1 (0x0000007f96650000)
        librcpputils.so => /usr/lib64/librcpputils.so (0x0000007f96630000)

Expected Behavior

can find the library

Actual Behavior

failed to find it.

To Reproduce

I simply croscompiled following,

$ wget https://raw.githubusercontent.com/ros2/ros2/release-foxy-20220208/ros2.repos
$ mkdir -p ros_ws/src
$ vcs import ros_ws/src < ros2.repos
$ ros_cross_compile ./ros_ws/ --arch aarch64 --os ubuntu --rosdistro foxy

System (please complete the following information)

For ROS 2 bugs - please attach a VCS.repos or Dockerfile if possible to help us reproduce the environment

Additional context

librmw_fastrtps_cpp.so relates code: https://github.com/ros2/rmw_fastrtps/blob/foxy/rmw_fastrtps_cpp/CMakeLists.txt#L107-L109

pojiro commented 2 years ago

Setting LD_LIBRARY_PATH explicitly to the execution environment resolves this issue.

However, I have not been able to figure out why it needs to be set explicitly, even though able to reference other ROS so's.

pojiro commented 2 years ago

Now I understand why this happend.

1. Who out put the error log ?

Failed to find library 'rmw_dds_common__rosidl_typesupport_fastrtps_cpp'

rosidl_typesupport did. following is the code

https://github.com/ros2/rosidl_typesupport/blob/bfb9d0cf20afe880c1e7659a43c328b255d799e5/rosidl_typesupport_cpp/src/type_support_dispatch.hpp#L67-L70

2. Who caused this error and Why?

Who: rcpputils::find_library_path caused by returning empty string.

https://github.com/ros2/rosidl_typesupport/blob/bfb9d0cf20afe880c1e7659a43c328b255d799e5/rosidl_typesupport_cpp/src/type_support_dispatch.hpp#L58-L65

Why: only search LD_LIBRARY_PATH env paths

https://github.com/ros2/rcpputils/blob/f4ce24de0b9b6b2c0c3807d6ce43418d4e1db331/src/find_library.cpp#L56-L71

3. Why ldd doesn't show the so, rmw_dds_common__rosidl_typesupport_fastrtps_cpp?

librmw_dds_common__rosidl_typesupport_fastrtps_cpp.so is loaded by dlopen.

below is the details

rcpputils::SharedLibrary constractor

https://github.com/ros2/rosidl_typesupport/blob/bfb9d0cf20afe880c1e7659a43c328b255d799e5/rosidl_typesupport_cpp/src/type_support_dispatch.hpp#L73

calls rcutils_load_shared_library, then it

https://github.com/ros2/rcpputils/blob/f4ce24de0b9b6b2c0c3807d6ce43418d4e1db331/src/shared_library.cpp#L27

calls dlopen.

https://github.com/ros2/rcutils/blob/dca53d39a14637673dcb9c6fae9f33e7e5a308b9/src/shared_library.c#L82

4. Is this a known issue?

Yes.

https://github.com/ros2/rcpputils/pull/122 has prompted improvements, but no action seems to have been taken yet.