如何处理由sysadmin安装在/usr/lib中的旧库
How to cope with older library installed in `/usr/lib` by sysadmin
我最近在一个超级计算机网格上有一个帐户,我正试图在他们的系统中编译我的代码。问题是程序不会链接以下错误:
/mnt/opt/tools/slc6/binutils/2.22/bin/ld: warning: libboost_system.so.1.55.0, needed by /mnt/home/jbzdak/tools/boost_1_55//lib/libboost_thread.so, may conflict with libboost_system.so.5
/mnt/opt/tools/slc6/binutils/2.22/bin/ld: /mnt/home/jbzdak/tools/boost_1_55//lib/libboost_thread.so: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
/mnt/opt/tools/slc6/binutils/2.22/bin/ld: note: '_ZN5boost6system15system_categoryEv' is defined in DSO /mnt/home/jbzdak/tools/boost_1_55//lib/libboost_system.so.1.55.0 so try adding it to the linker command line
/mnt/home/jbzdak/tools/boost_1_55//lib/libboost_system.so.1.55.0: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
这是因为我的程序需要boost 1.55,而/usr/lib64
的系统上只安装了1.39。我已经在本地文件夹中安装了我的boost版本,但不知何故,仍然先加载系统版本。
下面是传递给编译器的标志的摘录:
-std=gnu++11 -Werror -Wall -lboost_thread -lboost_filesystem -lboost_system -lboost_iostreams -g -DG4OPTIMISE -Iinclude
-W -Wall -ansi -pedantic -Wno-non-virtual-dtor -Wno-long-long -Wwrite-strings -Wpointer-arith -Woverloaded-virtual -pipe -O2
标志的完整列表在这里(它们应该是不相关的)。
以下是相关的配置变量:
LIBRARY_PATH /mnt/home/jbzdak/tools/boost_1_55/lib:
CPLUS_INCLUDE_PATH /mnt/home/jbzdak/tools/boost_1_55/include:/mnt/home/jbzdak/tools/geant4.9.6.3/compile/include/Geant4
LD_LIBRARY_PATH /mnt/home/jbzdak/tools/boost_1_55/lib:/mnt/opt/tools/slc6/gcc/4.8.3/lib64: ...
目录/mnt/home/jbzdak/tools/boost_1_55
包含已安装的boost库。
我使用GCC
4.8.3和ld
2.22。
我对链接器错误的经验很少,因此有这个问题。是否有任何方法可以排除/usr/lib64中的boost库,或者使链接器使用本地安装的库,并忽略系统库?
我在评论中说:
没有显示
-L/alternative/location/of/boost/lib
,所以编译器(链接器)不知道它需要在其他地方寻找您的现代Boost库。你可能也需要-Wl,rpath,/alternative/location/of/boost/lib
。
问题是:
为什么
LD_LIBRARY_PATH
没有解决这个问题?
因为LD_LIBRARY_PATH
是运行时变量而不是链接时变量。它影响/lib/ld.so.1
(或同等的)动态加载器在运行程序时查找库的位置,而不是链接器查找库的位置。
经过一些额外的调试和询问另一个问题,我找到了问题的根本原因。任何-L
参数都优先于LIBRARY_PATH
,并且不知何故添加了-L/usr/lib64
(因此它优先于我的版本)。
通过-v
参数检查发送给gcc
的选项。
相关文章:
- 在 /usr/local/lib 下找不到库
- bitbake-grpc交叉编译/配置失败,错误为c-ares::care引用文件/usr/lib/libcares.s
- C++ 可执行文件在运行时找不到库,即使它在 /usr/lib 中(在 Linux 上)
- 没有规则来设定目标'/usr/lib/x86_64-linux-gnu/libboost_filesystem.so'
- Java System.loadLibrary 不会在 /usr/lib/x86_64-linux-gnu/ 文件夹中查
- 带有定制 GLFW 二进制 /usr/bin/ld 的 Centos 7: /usr/local/lib/libglfw3.a(init.c.o):".text"部分中无法识别的重定位 (0x2a)
- C++: 错误: opencv_core: 即使所需的 .so 文件位于 /usr/lib/ 中,也没有这样的文件或目录
- ld:找不到文件:/usr/lib/crt1.o
- 如何将我的控制台应用程序链接到使用 clang++ 作为编译器的 OSX 环境中的 /usr/local/lib 中存在
- 如何在 C++ 中修复"/usr/bin/ld: warning: liblber-2.4.so.2, needed by //usr/lib/x86_64-linux-gnu/libcurl-gnu
- 在使用 bazel 构建一个简单的应用程序时,得到错误在 '/usr/lib/java/jdk1.8.0_74/bin/java' 找不到 java
- dyld:库未加载:libicui18n.54.dylib 引用自:/usr/local/lib/libxerces-c
- 使用/usr/lib/i386-linux-gnu而不是/usr/lib/x86_64-linux-gnu在CMake中
- G 不会链接到/usr/lib/中的库
- Cmake,在 /usr/local/include 中查找头文件,在 /usr/local/lib 中查找库
- "/usr/lib/libstdc .so.6: version `GLIBCXX_3.4.15' not found"是什么意思,我该如何解决?
- "/usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found`",如何解决?
- 捆绑的动态库:继续在/usr/local/lib中查找
- make[2]: *** 没有规则在 CGAL 中将目标 '/usr/lib/i386-linux-gnu/libmpfr.so'
- [UnixODBC][驱动程序管理器]无法打开 lib '/usr/lib/libmyodbc.so' :找不到文件,但文件存在