我如何让 Ubuntu 在某处查找库文件?

我如何让 Ubuntu 在某处查找库文件?

我已经将 OpenMPI 和一个名为 CVODE 的软件包安装到我的 Ubuntu 系统上,该系统在虚拟机中运行(使用 VirtualBox)。有一个问题,通过将一些库文件复制到 可以解决/usr/lib。换句话说,当我尝试 CVODE 附带的示例程序时,发生了以下情况:

$ mpirun ./cvAdvDiff_bnd 
cvAdvDiff_bnd: error while loading shared libraries: libsundials_cvode.so.1: cannot open shared object file: No such file or directory

$ sudo cp /home/jeff/sundials/instdir/lib/libsundials_cvode.so.1 /usr/lib/libsundials_cvode.so.1
$ mpirun cvAdvDiff_bnd
cvAdvDiff_bnd: error while loading shared libraries: libsundials_nvecserial.so.0: cannot open shared object file: No such file or directory

$ sudo cp /home/jeff/sundials/instdir/lib/libsundials_nvecserial.so.0 /usr/lib/libsundials_nvecserial.so.0
$ mpirun cvAdvDiff_bnd

2-D Advection-Diffusion Equation
Mesh dimensions = 10 X 5
Total system size = 50
Tolerance parameters: reltol = 0   abstol = 1e-05

At t = 0      max.norm(u) =  8.954716e+01 
At t = 0.10   max.norm(u) =  4.132889e+00   nst =   85
At t = 0.20   max.norm(u) =  1.039294e+00   nst =  103
At t = 0.30   max.norm(u) =  2.979829e-01   nst =  113
At t = 0.40   max.norm(u) =  8.765774e-02   nst =  120
At t = 0.50   max.norm(u) =  2.625637e-02   nst =  126
At t = 0.60   max.norm(u) =  7.830425e-03   nst =  130
At t = 0.70   max.norm(u) =  2.329387e-03   nst =  134
At t = 0.80   max.norm(u) =  6.953434e-04   nst =  137
At t = 0.90   max.norm(u) =  2.115983e-04   nst =  140
At t = 1.00   max.norm(u) =  6.556853e-05   nst =  142

Final Statistics:
nst = 142    nfe  = 174    nsetups = 23     nfeLS = 0      nje = 3
nni = 170    ncfn = 0      netf = 3

通过将这两个文件复制到 解决了查找这两个文件的问题/usr/lib。但是 中有数百个文件~/sundials/instdir/lib/

我怎样才能让 Ubuntu 在当前位置查找这些文件而不是将它们全部复制到/usr/lib/

答案1

使用LD_LIBRARY_PATHLD_PRELOAD环境变量,记录在man ld.so

有关的:

相关内容