给编译好的so修改rpath为当前路径

发布时间:2024年01月23日

  这几天调整安装,发现有些文件安装到/lib下。就想复制到安装目录,这样影响更少。然后发现rpaht有问题。怎么办?修改为当前路径最好。

  • 当前路径的两种表示方法

.或者$ORIGIN

NEW_RPATH=.:/usr/local/lib/:/lib/aarch64-linux-gnu/
NEW_RPATH=\$ORIGIN:/usr/local/lib/:/lib/aarch64-linux-gnu/

在编译的时候,大多使用$ORIGIN。因为$有特殊含义,所以这里进行了转义。

  • 办法1
patchelf --set-rpath ${RPATH} libopencv_video.so
  • 办法2
chrpath -r ${RPATH} libopencv_video.so
  • 修改前
# ldd libopencv_video.so
        linux-vdso.so.1 (0x0000007fa127c000)
        libopencv_imgproc.so.3.4 => /home/toybrick/work/libopencv_imgproc.so.3.4 (0x0000007fa0dd0000)
        libopencv_core.so.3.4 => /home/toybrick/work/libopencv_core.so.3.4 (0x0000007fa0aae000)
        libstdc++.so.6 => /lib/aarch64-linux-gnu/libstdc++.so.6 (0x0000007fa0923000)
        libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000007fa0866000)
        libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000007fa0842000)
        libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007fa06d0000)
        libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000007fa06bc000)
        libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000007fa068d000)
        libz.so.1 => /lib/aarch64-linux-gnu/libz.so.1 (0x0000007fa0660000)
        /lib/ld-linux-aarch64.so.1 (0x0000007fa124e000)
  • 修改后
# ldd libopencv_video.so
        linux-vdso.so.1 (0x0000007f9bb30000)
        libopencv_imgproc.so.3.4 => /home/toybrick/package/pan/./libopencv_imgproc.so.3.4 (0x0000007f9b6a7000)
        libopencv_core.so.3.4 => /home/toybrick/package/pan/./libopencv_core.so.3.4 (0x0000007f9b385000)
        libstdc++.so.6 => /lib/aarch64-linux-gnu/libstdc++.so.6 (0x0000007f9b1d7000)
        libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000007f9b11a000)
        libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000007f9b0f6000)
        libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007f9af84000)
        libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000007f9af70000)
        libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000007f9af41000)
        libz.so.1 => /lib/aarch64-linux-gnu/libz.so.1 (0x0000007f9af14000)
        /lib/ld-linux-aarch64.so.1 (0x0000007f9bb02000)

可以看到由编译的绝对路径,变成了相对路径。

文章来源:https://blog.csdn.net/quantum7/article/details/135767525
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。