sf包安装依赖GDAL (>= 2.0.1), GEOS (>= 3.4.0) and Proj.4 (>= 4.8.0)
如果服务器环境存在多个版本gdal安装过程比较复杂
过程
这里记录服务器存在两个版本的GDAL造成的安装过程
服务器上有自己用源码包安装的gdal(/usr/local/bin/gdal-config)和apt安装的gdal(/usr/bin/gdal-config)
并且版本不一样
/usr/local/bin/gdal-config --version
2.0.1
/usr/bin/gdal-config --version
2.2.2
这就造成了后面安装sf中很多麻烦
经历了install.package()安装失败后直接下载源码包进行安装
git clone https://hub.fastgit.org/r-spatial/sf.git
cd sf
R CMD INSTALL .
失败
Error: package or namespace load failed for ‘sf’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/mnt/sdb/chenyw/software/R/lib/R/library/00LOCK-sf/00new/sf/libs/sf.so':
/mnt/sdb/chenyw/software/R/lib/R/library/00LOCK-sf/00new/sf/libs/sf.so: undefined symbol: GDALTranslateOptionsFree
研究发现是sf.so库链接的库不对
ldd sf.so
linux-vdso.so.1 => (0x00007ffde3998000)
libproj.so.9 => /usr/lib/x86_64-linux-gnu/libproj.so.9 (0x00007f4408b9b000)
libgdal.so.20 => /usr/local/lib/libgdal.so.20 (0x00007f4407b66000)
libgeos_c.so.1 => /usr/lib/x86_64-linux-gnu/libgeos_c.so.1 (0x00007f4407938000)
libR.so => /usr/lib/libR.so (0x00007f4407386000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f4407004000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4406cfb000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4406ae5000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f440671b000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f44064fe000)
libsqlite3.so.0 => /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007f4406229000)
libodbc.so.2 => /usr/lib/x86_64-linux-gnu/libodbc.so.2 (0x00007f4405fc0000)
libodbcinst.so.2 => /usr/lib/x86_64-linux-gnu/libodbcinst.so.2 (0x00007f4405dae000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f4405b85000)
libxerces-c-3.1.so => /usr/lib/x86_64-linux-gnu/libxerces-c-3.1.so (0x00007f4405610000)
libjasper.so.1 => /usr/lib/x86_64-linux-gnu/libjasper.so.1 (0x00007f44053ba000)
libnetcdf.so.11 => /usr/lib/x86_64-linux-gnu/libnetcdf.so.11 (0x00007f4402057000)
libmfhdfalt.so.0 => /usr/lib/libmfhdfalt.so.0 (0x00007f4401e32000)
libdfalt.so.0 => /usr/lib/libdfalt.so.0 (0x00007f4401b8c000)
libgif.so.7 => /usr/lib/x86_64-linux-gnu/libgif.so.7 (0x00007f4401983000)
libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f440172a000)
libtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f44014b5000)
libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007f4401290000)
libpq.so.5 => /usr/lib/x86_64-linux-gnu/libpq.so.5 (0x00007f4401060000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f4400e46000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4400c42000)
libcurl.so.4 => /usr/lib/x86_64-linux-gnu/libcurl.so.4 (0x00007f44009d0000)
libxml2.so.2 => /usr/lib/x86_64-linux-gnu/libxml2.so.2 (0x00007f4400615000)
libgeos-3.5.1.so => /usr/lib/x86_64-linux-gnu/libgeos-3.5.1.so (0x00007f440027b000)
libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f440000c000)
libreadline.so.6 => /lib/x86_64-linux-gnu/libreadline.so.6 (0x00007f43ffdc6000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f43ffb56000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f43ff934000)
libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f43ff724000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f43ff51c000)
libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f43ff2fa000)
/lib64/ld-linux-x86-64.so.2 (0x00007f44090aa000)
libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007f43ff0f0000)
libicuuc.so.55 => /usr/lib/x86_64-linux-gnu/libicuuc.so.55 (0x00007f43fed5c000)
libhdf5_serial_hl.so.10 => /usr/lib/x86_64-linux-gnu/libhdf5_serial_hl.so.10 (0x00007f43feb3c000)
libhdf5_serial.so.10 => /usr/lib/x86_64-linux-gnu/libhdf5_serial.so.10 (0x00007f43fe69e000)
libcurl-gnutls.so.4 => /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4 (0x00007f43fe42e000)
libjbig.so.0 => /usr/lib/x86_64-linux-gnu/libjbig.so.0 (0x00007f43fe220000)
libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f43fdfb8000)
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f43fdb73000)
libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f43fd929000)
libldap_r-2.4.so.2 => /usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2 (0x00007f43fd6d8000)
libidn.so.11 => /usr/lib/x86_64-linux-gnu/libidn.so.11 (0x00007f43fd4a5000)
librtmp.so.1 => /usr/lib/x86_64-linux-gnu/librtmp.so.1 (0x00007f43fd289000)
liblber-2.4.so.2 => /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2 (0x00007f43fd07a000)
libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f43fce51000)
libicudata.so.55 => /usr/lib/x86_64-linux-gnu/libicudata.so.55 (0x00007f43fb39a000)
libsz.so.2 => /usr/lib/x86_64-linux-gnu/libsz.so.2 (0x00007f43fb197000)
libnettle.so.6 => /usr/lib/x86_64-linux-gnu/libnettle.so.6 (0x00007f43faf61000)
libgnutls.so.30 => /usr/lib/x86_64-linux-gnu/libgnutls.so.30 (0x00007f43fac31000)
libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f43fa95f000)
libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f43fa730000)
libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f43fa52c000)
libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f43fa321000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f43fa106000)
libsasl2.so.2 => /usr/lib/x86_64-linux-gnu/libsasl2.so.2 (0x00007f43f9eeb000)
libgssapi.so.3 => /usr/lib/x86_64-linux-gnu/libgssapi.so.3 (0x00007f43f9caa000)
libhogweed.so.4 => /usr/lib/x86_64-linux-gnu/libhogweed.so.4 (0x00007f43f9a77000)
libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f43f97f7000)
libaec.so.0 => /usr/lib/x86_64-linux-gnu/libaec.so.0 (0x00007f43f95ef000)
libp11-kit.so.0 => /usr/lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007f43f938b000)
libtasn1.so.6 => /usr/lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007f43f9178000)
libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f43f8f74000)
libheimntlm.so.0 => /usr/lib/x86_64-linux-gnu/libheimntlm.so.0 (0x00007f43f8d6b000)
libkrb5.so.26 => /usr/lib/x86_64-linux-gnu/libkrb5.so.26 (0x00007f43f8ae1000)
libasn1.so.8 => /usr/lib/x86_64-linux-gnu/libasn1.so.8 (0x00007f43f883f000)
libhcrypto.so.4 => /usr/lib/x86_64-linux-gnu/libhcrypto.so.4 (0x00007f43f860c000)
libroken.so.18 => /usr/lib/x86_64-linux-gnu/libroken.so.18 (0x00007f43f83f6000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f43f81ee000)
libwind.so.0 => /usr/lib/x86_64-linux-gnu/libwind.so.0 (0x00007f43f7fc5000)
libheimbase.so.1 => /usr/lib/x86_64-linux-gnu/libheimbase.so.1 (0x00007f43f7db6000)
libhx509.so.5 => /usr/lib/x86_64-linux-gnu/libhx509.so.5 (0x00007f43f7b6b000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f43f7933000)
libgdal.so.20 => /usr/local/lib/libgdal.so.20 (0x00007f4407b66000)
which gdal-config
/usr/bin/gdal-config
查看发现默认使用的是apt安装的gdal(2.2.2),而引用的库是/usr/local/lib/libgdal.so.20,源码安装的gdal(2.0.1)。所以虽然生成了sf.so文件但在载入时由于旧版的gdal的库的函数名的差异会找不到GDALTranslateOptionsFree。
解决
在编译过程中正确链接库文件即可。
echo $LD_LIBRARY_PATH
/usr/local/lib:/usr/lib:/usr/lib64
发现首要引用位置是/usr/local/lib。所以只要调换一下位置就好
export LD_LIBRARY_PATH="/usr/lib:$LD_LIBRARY_PATH"
再次安装
成功
再次查看sf.so
ldd src/sf.so
linux-vdso.so.1 => (0x00007ffc7f0cf000)
libproj.so.9 => /usr/lib/x86_64-linux-gnu/libproj.so.9 (0x00007f907a780000)
libgdal.so.20 => /usr/lib/libgdal.so.20 (0x00007f90795b8000)
libgeos_c.so.1 => /usr/lib/x86_64-linux-gnu/libgeos_c.so.1 (0x00007f907938a000)
libR.so => /usr/lib/libR.so (0x00007f9078dd8000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f9078a56000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f907874d000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f9078537000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f907816d000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9077f50000)
libarmadillo.so.6 => /usr/lib/libarmadillo.so.6 (0x00007f9077d48000)
libpoppler.so.58 => /usr/lib/x86_64-linux-gnu/libpoppler.so.58 (0x00007f90778c9000)
libjson-c.so.2 => /lib/x86_64-linux-gnu/libjson-c.so.2 (0x00007f90776be000)
libfreexl.so.1 => /usr/lib/x86_64-linux-gnu/libfreexl.so.1 (0x00007f90774b4000)
libqhull.so.7 => /usr/lib/x86_64-linux-gnu/libqhull.so.7 (0x00007f907725a000)
libwebp.so.5 => /usr/lib/x86_64-linux-gnu/libwebp.so.5 (0x00007f9076ffe000)
libepsilon.so.1 => /usr/lib/x86_64-linux-gnu/libepsilon.so.1 (0x00007f9076de6000)
libodbc.so.2 => /usr/lib/x86_64-linux-gnu/libodbc.so.2 (0x00007f9076b7d000)
libodbcinst.so.2 => /usr/lib/x86_64-linux-gnu/libodbcinst.so.2 (0x00007f907696b000)
libkmlbase.so.1 => /usr/lib/x86_64-linux-gnu/libkmlbase.so.1 (0x00007f9076751000)
libkmldom.so.1 => /usr/lib/x86_64-linux-gnu/libkmldom.so.1 (0x00007f9076498000)
libkmlengine.so.1 => /usr/lib/x86_64-linux-gnu/libkmlengine.so.1 (0x00007f907625e000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f9076035000)
libxerces-c-3.1.so => /usr/lib/x86_64-linux-gnu/libxerces-c-3.1.so (0x00007f9075ac0000)
libopenjp2.so.7 => /usr/lib/x86_64-linux-gnu/libopenjp2.so.7 (0x00007f9075884000)
libnetcdf.so.11 => /usr/lib/x86_64-linux-gnu/libnetcdf.so.11 (0x00007f9072521000)
libhdf5_serial.so.10 => /usr/lib/x86_64-linux-gnu/libhdf5_serial.so.10 (0x00007f9072083000)
libmfhdfalt.so.0 => /usr/lib/libmfhdfalt.so.0 (0x00007f9071e5e000)
libdfalt.so.0 => /usr/lib/libdfalt.so.0 (0x00007f9071bb8000)
libogdi.so.3.2 => /usr/lib/libogdi.so.3.2 (0x00007f9071997000)
libgif.so.7 => /usr/lib/x86_64-linux-gnu/libgif.so.7 (0x00007f907178e000)
libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f9071535000)
libgeotiff.so.2 => /usr/lib/x86_64-linux-gnu/libgeotiff.so.2 (0x00007f9071302000)
libtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f907108d000)
libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007f9070e68000)
libpq.so.5 => /usr/lib/x86_64-linux-gnu/libpq.so.5 (0x00007f9070c38000)
libdapclient.so.6 => /usr/lib/x86_64-linux-gnu/libdapclient.so.6 (0x00007f90709f9000)
libdap.so.17 => /usr/lib/x86_64-linux-gnu/libdap.so.17 (0x00007f907067b000)
libspatialite.so.7 => /usr/lib/x86_64-linux-gnu/libspatialite.so.7 (0x00007f906fef8000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f906fc88000)
libcurl-gnutls.so.4 => /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4 (0x00007f906fa18000)
libfyba.so.0 => /usr/lib/x86_64-linux-gnu/libfyba.so.0 (0x00007f906f7c3000)
libxml2.so.2 => /usr/lib/x86_64-linux-gnu/libxml2.so.2 (0x00007f906f408000)
libmysqlclient.so.20 => /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20 (0x00007f906ee51000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f906ec37000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f906ea33000)
libgeos-3.5.1.so => /usr/lib/x86_64-linux-gnu/libgeos-3.5.1.so (0x00007f906e699000)
libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f906e42a000)
libreadline.so.6 => /lib/x86_64-linux-gnu/libreadline.so.6 (0x00007f906e1e4000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f906dfc2000)
libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f906ddb2000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f906dbaa000)
libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f906d988000)
/lib64/ld-linux-x86-64.so.2 (0x00007f907ac8f000)
liblapack.so.3 => /usr/lib/liblapack.so.3 (0x00007f906d190000)
libarpack.so.2 => /usr/lib/libarpack.so.2 (0x00007f906cf45000)
libsuperlu.so.4 => /usr/lib/x86_64-linux-gnu/libsuperlu.so.4 (0x00007f906ccd9000)
liblcms2.so.2 => /usr/lib/x86_64-linux-gnu/liblcms2.so.2 (0x00007f906ca82000)
libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f906c83f000)
libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f906c595000)
libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007f906c38b000)
libminizip.so.1 => /usr/lib/x86_64-linux-gnu/libminizip.so.1 (0x00007f906c180000)
liburiparser.so.1 => /usr/lib/x86_64-linux-gnu/liburiparser.so.1 (0x00007f906bf65000)
libicuuc.so.55 => /usr/lib/x86_64-linux-gnu/libicuuc.so.55 (0x00007f906bbd1000)
libhdf5_serial_hl.so.10 => /usr/lib/x86_64-linux-gnu/libhdf5_serial_hl.so.10 (0x00007f906b9b1000)
libsz.so.2 => /usr/lib/x86_64-linux-gnu/libsz.so.2 (0x00007f906b7ae000)
libjbig.so.0 => /usr/lib/x86_64-linux-gnu/libjbig.so.0 (0x00007f906b5a0000)
libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f906b338000)
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f906aef3000)
libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f906aca9000)
libldap_r-2.4.so.2 => /usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2 (0x00007f906aa58000)
libsqlite3.so.0 => /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007f906a783000)
libidn.so.11 => /usr/lib/x86_64-linux-gnu/libidn.so.11 (0x00007f906a550000)
librtmp.so.1 => /usr/lib/x86_64-linux-gnu/librtmp.so.1 (0x00007f906a334000)
libnettle.so.6 => /usr/lib/x86_64-linux-gnu/libnettle.so.6 (0x00007f906a0fe000)
libgnutls.so.30 => /usr/lib/x86_64-linux-gnu/libgnutls.so.30 (0x00007f9069dce000)
liblber-2.4.so.2 => /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2 (0x00007f9069bbf000)
libfyut.so.0 => /usr/lib/x86_64-linux-gnu/libfyut.so.0 (0x00007f90699b5000)
libfygm.so.0 => /usr/lib/x86_64-linux-gnu/libfygm.so.0 (0x00007f90697ae000)
libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f9069585000)
libgfortran.so.3 => /usr/lib/x86_64-linux-gnu/libgfortran.so.3 (0x00007f906925a000)
libicudata.so.55 => /usr/lib/x86_64-linux-gnu/libicudata.so.55 (0x00007f90677a3000)
libaec.so.0 => /usr/lib/x86_64-linux-gnu/libaec.so.0 (0x00007f906759b000)
libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f90672c9000)
libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f906709a000)
libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f9066e96000)
libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f9066c8b000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f9066a70000)
libsasl2.so.2 => /usr/lib/x86_64-linux-gnu/libsasl2.so.2 (0x00007f9066855000)
libgssapi.so.3 => /usr/lib/x86_64-linux-gnu/libgssapi.so.3 (0x00007f9066614000)
libhogweed.so.4 => /usr/lib/x86_64-linux-gnu/libhogweed.so.4 (0x00007f90663e1000)
libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f9066161000)
libp11-kit.so.0 => /usr/lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007f9065efd000)
libtasn1.so.6 => /usr/lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007f9065cea000)
libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f9065aab000)
libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f90658a7000)
libheimntlm.so.0 => /usr/lib/x86_64-linux-gnu/libheimntlm.so.0 (0x00007f906569e000)
libkrb5.so.26 => /usr/lib/x86_64-linux-gnu/libkrb5.so.26 (0x00007f9065414000)
libasn1.so.8 => /usr/lib/x86_64-linux-gnu/libasn1.so.8 (0x00007f9065172000)
libhcrypto.so.4 => /usr/lib/x86_64-linux-gnu/libhcrypto.so.4 (0x00007f9064f3f000)
libroken.so.18 => /usr/lib/x86_64-linux-gnu/libroken.so.18 (0x00007f9064d29000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f9064b21000)
libwind.so.0 => /usr/lib/x86_64-linux-gnu/libwind.so.0 (0x00007f90648f8000)
libheimbase.so.1 => /usr/lib/x86_64-linux-gnu/libheimbase.so.1 (0x00007f90646e9000)
libhx509.so.5 => /usr/lib/x86_64-linux-gnu/libhx509.so.5 (0x00007f906449e000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f9064266000)
发现所引用的libgdal.so.20位置已经正确