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