3

我尝试在 docker 容器中设置 FastRTPS。我编写了一个 Dockerfile,它构建 FastRTPS 及其从源代码的依赖项,并安装库和交付的示例。但是这些例子不起作用:

/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

由于这些库是在此容器中构建并自动安装的,因此它必须在某个地方并且它们在这里:

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

也可以查看这个库# nm -D /usr/local/lib/libfastrtps.so.1

但是的输出ldconfig有点奇怪:

# 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:

在这里,我期望列出的库,但事实并非如此。

如何解决?


编辑 1 在构建 FastRTPS 时从 make 输出中提取一些内容:

...
-- 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 ""

为什么运行时路径设置为""- 无?

4

1 回答 1

1

最后一次编辑导致了问题以及解决方案。

CMake 删除RPATH. 如果在 docker 容器中使用,这种剥离是没有意义的,可以通过将这个参数添加到 CMake 配置调用中来关闭,如本文所述:

-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE

最后我的 Dockerfile 看起来像这样:

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

现在 install-step 输出显示正确的运行时路径设置:

-- Installing: /usr/local/examples/C++/HelloWorldExample/HelloWorldExample
-- Set runtime path of "/usr/local/examples/C++/HelloWorldExample/HelloWorldExample" to "/usr/local/lib"
于 2020-03-27T14:58:07.820 回答