3

I try to set up FastRTPS inside a docker container. I wrote a Dockerfile which builds FastRTPS and it's dependencies from source and installs the libraries and delivered examples. But the examples do not work:

/opt# /usr/local/examples/C++/HelloWorldExample/bin/HelloWorldExample 
/usr/local/examples/C++/HelloWorldExample/bin/HelloWorldExample: error while loading shared libraries: libfastrtps.so.1: cannot open shared object file: No such file or directory

As these library was built in this container and automatically installed, it must be somewhere and they are here:

root@6e544f0699cf:/opt# ls -la /usr/local/lib/
total 9196
drwxr-xr-x 1 root root     4096 Mar 26 22:02 .
drwxr-xr-x 1 root root     4096 Mar 26 22:02 ..
drwxr-xr-x 3 root root     4096 Mar 26 22:00 cmake
drwxr-xr-x 3 root root     4096 Mar 26 22:00 foonathan_memory
lrwxrwxrwx 1 root root       15 Mar 26 22:00 libfastcdr.so -> libfastcdr.so.1
lrwxrwxrwx 1 root root       20 Mar 26 22:00 libfastcdr.so.1 -> libfastcdr.so.1.0.12
-rw-r--r-- 1 root root    99504 Mar 26 22:00 libfastcdr.so.1.0.12
lrwxrwxrwx 1 root root       16 Mar 26 22:02 libfastrtps.so -> libfastrtps.so.1
lrwxrwxrwx 1 root root       21 Mar 26 22:02 libfastrtps.so.1 -> libfastrtps.so.1.10.0
-rw-r--r-- 1 root root  8133952 Mar 26 22:01 libfastrtps.so.1.10.0
-rw-r--r-- 1 root root  1158048 Mar 26 22:00 libfoonathan_memory-0.6.2.a
drwxrwsr-x 3 root staff    4096 Mar 26 21:37 python3.7

It is also possible to look into this library # nm -D /usr/local/lib/libfastrtps.so.1.

But the output of ldconfig is a bit strange:

# ldconfig -v | grep /usr/local/lib
ldconfig: Can't stat /usr/local/lib/x86_64-linux-gnu: No such file or directory
ldconfig: Path `/lib/x86_64-linux-gnu' given more than once
ldconfig: Path `/usr/lib/x86_64-linux-gnu' given more than once
ldconfig: /lib/x86_64-linux-gnu/ld-2.28.so is the dynamic linker, ignoring

/usr/local/lib:

Here I expected the libraries listed but they are not.

How to fix that?


EDIT 1 some extractions from the make output while building FastRTPS:

...
-- Installing: /usr/local/lib/libfastrtps.so.1.10.0
-- Installing: /usr/local/lib/libfastrtps.so.1
-- Installing: /usr/local/lib/libfastrtps.so
...
-- Installing: /usr/local/examples/C++/HelloWorldExample/bin/HelloWorldExample
-- Set runtime path of "/usr/local/examples/C++/HelloWorldExample/bin/HelloWorldExample" to ""

Why the runtime path is set to "" - nothing?

Alex44
  • 3,597
  • 7
  • 39
  • 56

1 Answers1

1

The last edit led to the issue and also to the solution.

CMake removes the RPATH. In case of the usage within a docker container, this stripping makes no sense and can be turned off as described in this post by adding this argument to the CMake configuration call:

-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE

At the end my Dockerfile looks like this:

FROM fastrtps-core

WORKDIR /opt
RUN git clone https://github.com/eProsima/Fast-RTPS.git && \
    export LDFLAGS="-Wl,--copy-dt-needed-entries" && \
    mkdir build && \
    cd build && \
    cmake ../Fast-RTPS/examples \
        -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE && \
    cmake --build . --target install -j 16 && \
    cd /opt && \
    rm -rf build Fast-RTPS

Now the install-step output shows the correct runtime-path setting:

-- Installing: /usr/local/examples/C++/HelloWorldExample/HelloWorldExample
-- Set runtime path of "/usr/local/examples/C++/HelloWorldExample/HelloWorldExample" to "/usr/local/lib"
Alex44
  • 3,597
  • 7
  • 39
  • 56