【问题标题】:Linux: Can't find existing shared library in docker containerLinux:在 docker 容器中找不到现有的共享库
【发布时间】:2020-03-26 22:29:44
【问题描述】:

我尝试在 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 ""

为什么运行时路径设置为"" - 什么都没有?

【问题讨论】:

    标签: linux docker shared-libraries


    【解决方案1】:

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

    CMake 删除了RPATH。如果在 docker 容器中使用,这种剥离是没有意义的,可以按照post 中的描述通过将此参数添加到 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
    

    现在安装步骤输出显示正确的运行时路径设置:

    -- Installing: /usr/local/examples/C++/HelloWorldExample/HelloWorldExample
    -- Set runtime path of "/usr/local/examples/C++/HelloWorldExample/HelloWorldExample" to "/usr/local/lib"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-18
      • 2020-12-06
      • 1970-01-01
      • 2011-06-12
      相关资源
      最近更新 更多