RNetCDF无法打开共享对象文件。

6

我正在尝试在我的笔记本电脑上(Ubuntu 12.04)使用命令安装 RNetCDF 包:

install.packages('RNetCDF',lib='/home/my_computer/RSCRIPTS/R_LIB/',configure.args="--with-netcdf-include='/home/my_computer/bin/libs4cdo-0.0.10/netcdf-4.2/include/' --with-netcdf-lib='/home/my_computer/local/bin' --with-hdf5-lib='/home/my_computer/local/lib/' --with-udunits-include='/usr/local/lib/' --with-udunits-lib='/usr/local/lib/'",repos='http://star-www.st-andrews.ac.uk/cran/')

但是这个软件包无法安装。请看下面的错误信息:
trying URL 'http://star-www.st-andrews.ac.uk/cran/src/contrib/RNetCDF_1.6.1-2.tar.gz'
Content type 'application/x-gzip' length 70301 bytes (68 Kb)
opened URL
==================================================
downloaded 68 Kb

* installing *source* package ‘RNetCDF’ ...
** package ‘RNetCDF’ successfully unpacked and MD5 sums checked
checking for gcc... gcc -std=gnu99
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc -std=gnu99 accepts -g... yes
checking for gcc -std=gnu99 option to accept ISO C89... none needed
checking for nc_open in -lnetcdf... yes
checking for utInit in -ludunits2... no
checking for utScan in -ludunits2... yes
checking how to run the C preprocessor... gcc -std=gnu99 -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking netcdf.h usability... yes
checking netcdf.h presence... yes
checking for netcdf.h... yes
checking udunits.h usability... yes
checking udunits.h presence... yes
checking for udunits.h... yes
configure: creating ./config.status
config.status: creating R/load.R
config.status: creating src/Makevars
** libs
gcc -std=gnu99 -I/usr/share/R/include -I/usr/local/lib/ -I/home/bauduinm/bin/libs4cdo-0.0.10/netcdf-4.2/include/      -fpic  -O3 -pipe  -g -c RNetCDF.c -o RNetCDF.o
gcc -std=gnu99 -shared -o RNetCDF.so RNetCDF.o -ludunits2 -lnetcdf -L/home/my_computer/local/lib/ -L/usr/local/lib/ -L/home/my_computer/local/bin -lexpat -L/usr/lib/R/lib -lR
installing to /home/my_computer/RSCRIPTS/R_LIB/RNetCDF/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices ...
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
 unable to load shared object '/home/my_computer/RSCRIPTS/R_LIB/RNetCDF  /libs/RNetCDF.so':
libexpat.so.0: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed  
* removing ‘/home/my_computer/RSCRIPTS/R_LIB/RNetCDF’

The downloaded packages are in
‘/tmp/Rtmpl5MniY/downloaded_packages’
Warning message:
In install.packages("RNetCDF", lib = "/home/my_computer/RSCRIPTS/R_LIB/",  :
    installation of package ‘RNetCDF’ had non-zero exit status

当我尝试使用

sudo R CMD INSTALL --libary='/home/my_computer/RSCRIPTS/R_LIB/' --configure-args="--with-netcdf-include='/home/my_computer/bin/libs4cdo-0.0.10/netcdf-4.2/include/' --with-netcdf-lib='/home/my_computer/local/lib/' --with-hdf5-lib='/home/my_computer/local/lib/' --with-udunits-include=/usr/local/lib/ --with-udunits-lib=/usr/local/lib/" /home/my_computer/Downloads/RNetCDF_1.6.1-2.tar.gz

错误信息已被替换为:
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
unable to load shared object '/usr/local/lib/R/site-library/RNetCDF/libs/RNetCDF.so':
  libnetcdf.so.7: cannot open shared object file: No such file or directory

libnetcdf.so.7绝对位于/home/my_computer/local/lib/,这也是我的LD_LIBRARY_PATH。不可否认,libexpat.so.0是第一个错误信息中的文件之一(使用install.packages),位于与netcdf库无关的intel相关文件夹中。

有人能给我指点吗?

谢谢。

编辑:好吧,我永远不会知道发生了什么,因为当我在3天后再次尝试使用完全相同的install.packages命令行时,软件包毫无问题地安装了...所以我唯一的建议是退出R并重新开始,以防先前会话中的某些错误留在日志中。


1
在您第一次尝试加载库时,它是否真的在此路径中有一个空格:/home/my_computer/RSCRIPTS/R_LIB/RNetCDF /libs/RNetCDF.so,还是当您将其粘贴到SO时出现了格式问题? - nograpes
此外,阅读关于链接 libexpat.so.0这篇帖子。如果您安装了更新版本(我猜您可能已经安装了),则可以使用链接将软件包指向正确的位置(如帖子中所示)。 - nograpes
@nograpes 感谢您的评论。这迫使我查看了空间问题(这是SO格式问题),重新运行命令行并意识到我今天可以无问题地安装该软件包。 - SnowFrog
1个回答

3
尝试在R CMD INSTALL中添加--no-test-load,这样可以避免安装过程中出现错误。
然后,在正常的R会话中使用library(RNetCDF)检查是否可以加载这个软件包。如果由于“无法加载共享对象”错误而失败:
1. 使用Sys.getenv("LD_LIBRARY_PATH")检查R是否使用了您的$LD_LIBRARY_PATH。 2. 查看ldd /usr/local/lib/R/site-library/RNetCDF/libs/RNetCDF.so的输出,看看libnetcdf.so.7是否被解析为已包含在R的LD_LIBRARY_PATH中的路径。
顺便说一句,我使用Ubuntu自带的libnetcdf(通过apt-get install libnetcdf-dev [version 4.1.1])安装RNetCDF时没有遇到问题;除非您确实需要libnetcdf的4.2版本,否则可以尝试这种方法。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接