Linux:在Docker容器中找不到现有的共享库 [英] Linux: Can't find existing shared library in docker container

查看:212
本文介绍了Linux:在Docker容器中找不到现有的共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在docker容器内设置FastRTPS.我写了一个Dockerfile,它构建FastRTPS及其从源代码的依赖关系,并安装库和提供的示例.但是这些示例不起作用:

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

也可以查看此库#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:

我在这里期望列出的库,但是没有.

Here I expected the libraries listed but they are not.

该如何解决?

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

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?

推荐答案

最后的修改导致了问题,也导致了解决方案.

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

CMake删除 RPATH .如果在Docker容器中使用,则这种剥离是没有意义的,可以按照此

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

最后,我的Dockerfile如下所示:

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"

这篇关于Linux:在Docker容器中找不到现有的共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆