记录一个R包安装过程的报错及解决【libpng版本问题】
0. 关键词
R包安装报错:
无法载入共享目标对象( unable to load shared object )
1. 背景
需要安装的R包:png
操作系统:Ubuntu
2. 报错
#' 本地安装 png 包 install.packages("png_0.1-7.tar.gz", repos = NULL, type = "source") ## Error: package or namespace load failed for ‘png’ in dyn.load(file, DLLpath = DLLpath, ...): ## 无法载入共享目标对象‘/home/liangchen/R/x86_64-pc-linux-gnu-library/3.4/png/libs/png.so’:: ## libpng16.so.16: cannot open shared object file: No such file or directory ## 错误: 载入失败 ## 停止执行 ## ERROR: loading failed
3. 解决
从报错信息来看,是系统库的问题。一般来说,系统库的问题可能是:a) 系统库缺失;b) 系统库版本不对。
3.1 尝试一:apt-get install
apt-get install libpng-dev ## Reading package lists... Done ## Building dependency tree ## Reading state information... Done ## Note, selecting 'libpng12-dev' instead of 'libpng-dev' ## The following additional packages will be installed: ## libpng12-0 ## The following packages will be upgraded: ## libpng12-0 libpng12-dev ## 2 upgraded, 0 newly installed, 0 to remove and 532 not upgraded. ## 2 not fully installed or removed. ## Need to get 300 kB of archives. ## After this operation, 0 B of additional disk space will be used. ## Do you want to continue? [Y/n] n ## Abort.
apt-get install 并不能安装 libpng16.so.16 ,故放弃。
3.2 尝试二:拷贝
cd /usr/lib/x86_64-linux-gnu cp /usr/local/software/anaconda3/lib/libpng16.so.16* . ldconfig ## /sbin/ldconfig.real: /usr/lib/x86_64-linux-gnu/libpng16.so.16 is not a symbolic link
3.3 尝试三:软链
cd /usr/lib/x86_64-linux-gnu cp /usr/local/software/anaconda3/lib/libpng16.so.16.28.0 . ln -sf libpng16.so.16.28.0 libpng16.so.16 ldconfig
之后就可以顺利安装 png 包了。
4. 附背景信息(其实没什么关系):
> sessionInfo() R version 3.4.0 (2017-04-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 16.04.3 LTS Matrix products: default BLAS: /usr/lib/libblas/libblas.so.3.6.0 LAPACK: /usr/lib/lapack/liblapack.so.3.6.0 locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] compiler_3.4.0