linux动态库找不到

linux动态库找不到

  • 一、分析
  • 二、解决
    • 方式一
    • 方式二
    • 方式三
  • 三、如何检查RPATH的值

问题状态:xxx.so: cannot open shared object file: No such file or directory

一、分析

首先要知道linux寻找动态链接库的顺序
1.编译目标代码时指定的动态库搜索路径(-L选项明文指定的目录)
2.环境变量LD_LIBRARY_PATH指定的动态库搜索路径;
3.配置文件/etc/ld.so.conf中指定的动态库搜索路径;
4.默认的动态库搜索路径/lib;
5.默认的动态库搜索路径/usr/lib

二、解决

方式一

1,将缺少的库文件拷贝到指定目录下
2,通过 export LD_LIBRARY_PATH=yourpath/lib

方式二

1,将缺少的库文件拷贝到指定目录下
2,将libhello.so拷贝到/usr/local/lib,然后运行ldconfig

方式三

1,将缺少的库文件拷贝到指定目录下
2,使用RPATH

//RPATH设置当前路径
$(CROSS)g++ $(CFLAGS) -Wl,-rpath,'$$ORIGIN'  -o $@ $^ $(LIBSO) -Xlinker "-(" $(LIBS) -Xlinker "-)"  $(LFLAGS)
//RPATH设置指定路径:../../flyCV/flycv/aarch64/
$(CROSS)g++ $(CFLAGS) -Wl,-rpath,'../../flyCV/flycv/aarch64/'  -o $@ $^ $(LIBSO) -Xlinker "-(" $(LIBS) -Xlinker "-)"  
$(LFLAGS)  

三、如何检查RPATH的值

有多种方法可以检查可执行文件或库的RPATH值。objdump、readelf和chrpath是3个常用的实用程序。

//反汇编
jetson@Nano:/mnt/demoITA/test_app/src$ objdump -x guideman | grep RPATH
  RPATH                $ORIGIN
//反汇编关键函数
objdump -d guideman | grep ITA
//readelf
jetson@Nano:/mnt/demoITA/test_app/src$ readelf -d guideman | head -20

Dynamic section at offset 0x5d28 contains 33 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [../../ITALib/ITA_VER02/ITALib_test/lib/libITA.so]
 0x0000000000000001 (NEEDED)             Shared library: [libflycv_shared.so]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-aarch64.so.1]
 0x000000000000000f (RPATH)              Library rpath: [../../flyCV/flycv/aarch64/]
 0x000000000000000c (INIT)               0x4022a0
 0x000000000000000d (FINI)               0x404104
 0x0000000000000019 (INIT_ARRAY)         0x415c58
 0x000000000000001b (INIT_ARRAYSZ)       32 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x415c78
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x0000000000000004 (HASH)               0x400298

你可能感兴趣的:(linux,bash,运维)