如何处理由sysadmin安装在/usr/lib中的旧库

How to cope with older library installed in `/usr/lib` by sysadmin

本文关键字:lib usr 理由 sysadmin 安装 何处      更新时间:2023-10-16

我最近在一个超级计算机网格上有一个帐户,我正试图在他们的系统中编译我的代码。问题是程序不会链接以下错误:

/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的选项。

相关文章: