本文介绍了如何将共享库搜索路径添加到可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用librtmp构建ffmpeg.我的librtmp位于/opt/librtmp/lib.当我执行ffmpeg时,它说:

I build the ffmpeg with librtmp. My librtmp is at /opt/librtmp/lib. When I execute the ffmpeg, it said:

./ffmpeg: error while loading shared libraries: librtmp.so.0: cannot open shared object file: No such file or directory

我使用ldd命令,它显示未找到:

I use ldd command it displays not found:

[qty@testing bin]# ldd ffmpeg
        linux-vdso.so.1 =>  (0x00007fff15576000)
        librtmp.so.0 => not found
        libz.so.1 => /lib64/libz.so.1 (0x00002b9a71e10000)
        libm.so.6 => /lib64/libm.so.6 (0x00002b9a72025000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00002b9a722a8000)
        libc.so.6 => /lib64/libc.so.6 (0x00002b9a724c3000)
        /lib64/ld-linux-x86-64.so.2 (0x00002b9a71bf2000)

我知道我的所在:

[qty@testing bin]# ls -alh  /opt/librtmp/lib/
total 300K
drwxr-xr-x 3 root root 4.0K Sep 25 17:10 .
drwxr-xr-x 7 root root 4.0K Sep 25 17:10 ..
-rw-r--r-- 1 root root 158K Sep 25 17:10 librtmp.a
lrwxrwxrwx 1 root root   12 Sep 25 17:10 librtmp.so -> librtmp.so.0
-rwxr-xr-x 1 root root 118K Sep 25 17:10 librtmp.so.0
drwxr-xr-x 2 root root 4.0K Sep 25 17:10 pkgconfig

我找到了解决问题的几种方法

I found several ways to fix the problem

  • 修改/etc/ld.so.conf,但需要超级用户
  • 设置LD_LIBRARY_PATH变量,但对用户而言不方便
  • 像这样将rpath传递给gcc

为我的ffmpeg配置args

PKG_CONFIG_PATH="/opt/librtmp/lib/pkgconfig" ./configure --disable-doc \
--disable-ffserver --disable-avdevice \
--disable-postproc --disable-avfilter --disable-bsfs \
--disable-filters \
--disable-asm \
--disable-bzlib \
--enable-librtmp \
--prefix=/opt/ffmpeg \
--extra-ldflags="-Wl,-rpath,/opt/librtmp/lib"

假设没有源代码可以重新编译?如何将共享库搜索路径添加到可执行文件?

Assume there are no source code to re-compile? How do add the shared library search path to a executable file ?

推荐答案

您可以使用 addrpath 将RPATH添加到您的elf文件中.

You could use addrpath to add an RPATH to your elf file.

RPATH将像LD_LIBRARY_PATH一样工作,也就是说,告诉动态加载程序在该路径中搜索共享库. RPATH将永久存在于您的ELF文件中.

The RPATH will work like LD_LIBRARY_PATH, that is, telling the dynamic loader to search for the shared libraries in that path. RPATH will be permanently in your ELF file.

这篇关于如何将共享库搜索路径添加到可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-28 16:33