解决 error while loading shared libraries: libfastdb.so.2

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sea_snow/article/details/82179905

在使用fastdb的动态库时,遇到如下问题,其他项目依然可以参考

error while loading shared libraries: libfastdb.so.2: cannot open shared object file: No such file or directory

1、问题分析

编译的时候,使用   g++ FastDb.cpp -I fastdb/inc  -L fastdb/libs -lfastdb

可以链接到库完成编译,但是运行的时候,其实还是没有找到对应的库

2、解决方案

编译的时候,使用 g++ FastDb.cpp -I fastdb/inc -Wl,-rpath=fastdb/libs -L fastdb/libs -lfastdb

-Wl 表示编译器将后面的参数传递给链接器ld

-rpath 

 a. 添加一个文件夹作为运行时的搜索路径

 b. 在链接是,一些动态库明确的链接了其他动态库,-rpath选项用于定位这些依赖的动态库

你也可以参考,如下方式尝试

flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

猜你喜欢

转载自blog.csdn.net/sea_snow/article/details/82179905