本文主要是介绍给编译好的so修改rpath为当前路径,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
这几天调整安装,发现有些文件安装到/lib下。就想复制到安装目录,这样影响更少。然后发现rpath有问题。怎么办?修改为当前路径最好。
- 当前路径的两种表示方法
.或者$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 ${NEW_RPATH} libopencv_video.so
- 办法2
chrpath -r ${NEW_RPATH} libopencv_video.so
- 修改前
$ ldd libopencv_video.solinux-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.solinux-vdso.so.1 (0x0000007f9bb30000)libopencv_imgproc.so.3.4 => /home/toybrick/package/./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)
可以看到由编译的绝对路径,变成了相对路径。
这篇关于给编译好的so修改rpath为当前路径的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!