在Ubuntu 16.04上安装rgdal的更多问题-未定义符号

时间:2018-08-09 21:08:02

标签: r ubuntu-16.04 gdal rgdal

我一直在尝试讨论如何将rgdal安装到Ubuntu 16.04的许多线程上的各种建议,但仍然遇到麻烦。

在经过多次错误尝试之后,这就是我要去的地方。我在这里(trouble in installing rgdal on ubuntu 16.04)尝试了答案:

sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
sudo apt update
sudo apt install gdal-bin python-gdal python3-gdal libgdal1-dev

除了libgdal1-dev以外,我的软件包管理器说可用的版本是1.11.3,这几乎可以解决我的问题(不确定在此阶段是否可以复制),所以我使用了Synaptic卸载该软件包并安装由Synaptic标记的libgdal-dev。

因此,根据Synaptic的说明,当我搜索“ gdal”时,显示的已安装文件为gdal-bin,gdal-data,libgdal-dev,libgdal20,python-gdal和python3-盖达尔。

这时,当我打开R并运行install.packages("rgdal")时,我会得到以下结果:

Installing package into ‘/home/[username]/R/x86_64-pc-linux-gnu-library/3.4’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/rgdal_1.3-4.tar.gz'
Content type 'application/x-gzip' length 1664774 bytes (1.6 MB)
==================================================
downloaded 1.6 MB

* installing *source* package ‘rgdal’ ...
** package ‘rgdal’ successfully unpacked and MD5 sums checked
configure: R_HOME: /usr/lib/R
configure: CC: gcc -std=gnu99
configure: CXX: g++
configure: C++11 support available
configure: rgdal: 1.3-4
checking for /usr/bin/svnversion... no
configure: svn revision: 766
checking for gdal-config... /usr/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 2.2.2
checking GDAL version >= 1.11.4... yes
checking gdal: linking with --libs only... yes
checking GDAL: /usr/share/gdal/2.2/pcs.csv readable... yes
configure: pkg-config proj exists, will use it
configure: PROJ version: 4.9.2
checking proj_api.h presence and usability... yes
checking PROJ version >= 4.8.0... yes
checking projects.h presence and usability... yes
checking PROJ.4: epsg found and readable... yes
checking PROJ.4: conus found and readable... yes
configure: Package CPP flags:  -I/usr/include/gdal
configure: Package LIBS:  -L/usr/lib -lgdal -lproj
configure: creating ./config.status
config.status: creating src/Makevars
** libs
g++ -std=gnu++11 -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I"/home/[username]/R/x86_64-pc-linux-gnu-library/3.4/sp/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c OGR_write.cpp -o OGR_write.o
g++ -std=gnu++11 -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I"/home/[username]/R/x86_64-pc-linux-gnu-library/3.4/sp/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c gdal-bindings.cpp -o gdal-bindings.o
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I"/home/[username]/R/x86_64-pc-linux-gnu-library/3.4/sp/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c init.c -o init.o
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I"/home/[username]/R/x86_64-pc-linux-gnu-library/3.4/sp/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c inverser.c -o inverser.o
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I"/home/[username]/R/x86_64-pc-linux-gnu-library/3.4/sp/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c local_stubs.c -o local_stubs.o
g++ -std=gnu++11 -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I"/home/[username]/R/x86_64-pc-linux-gnu-library/3.4/sp/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c ogr_geom.cpp -o ogr_geom.o
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I"/home/[username]/R/x86_64-pc-linux-gnu-library/3.4/sp/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c ogr_polygons.c -o ogr_polygons.o
g++ -std=gnu++11 -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I"/home/[username]/R/x86_64-pc-linux-gnu-library/3.4/sp/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c ogr_proj.cpp -o ogr_proj.o
g++ -std=gnu++11 -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I"/home/[username]/R/x86_64-pc-linux-gnu-library/3.4/sp/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c ogrdrivers.cpp -o ogrdrivers.o
g++ -std=gnu++11 -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I"/home/[username]/R/x86_64-pc-linux-gnu-library/3.4/sp/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c ogrsource.cpp -o ogrsource.o
g++ -std=gnu++11 -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I"/home/[username]/R/x86_64-pc-linux-gnu-library/3.4/sp/include"    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c projectit.cpp -o projectit.o
g++ -std=gnu++11 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o rgdal.so OGR_write.o gdal-bindings.o init.o inverser.o local_stubs.o ogr_geom.o ogr_polygons.o ogr_proj.o ogrdrivers.o ogrsource.o projectit.o -L/usr/lib -lgdal -lproj -L/usr/lib/R/lib -lR
installing to /home/[username]/R/x86_64-pc-linux-gnu-library/3.4/rgdal/libs
** R
** data
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error: package or namespace load failed for ‘rgdal’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/[username]/R/x86_64-pc-linux-gnu-library/3.4/rgdal/libs/rgdal.so':
  /home/[username]/R/x86_64-pc-linux-gnu-library/3.4/rgdal/libs/rgdal.so: undefined symbol: _ZN10OGRFeature17GetFieldAsIntegerEi
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/[username]/R/x86_64-pc-linux-gnu-library/3.4/rgdal’

The downloaded source packages are in
    ‘/tmp/Rtmpuc6qcT/downloaded_packages’
Warning message:
In install.packages("rgdal") :
  installation of package ‘rgdal’ had non-zero exit status

我搜索了错误消息,发现了这个问题(Cannot install rgdal package in R on RHEL6, unable to load shared object rgdal.so),因此尝试运行

ldconfig -c "echo '/usr/local/lib' >> /etc/ld.so.conf.d/R-dependencies-x86_64.conf"

但是它似乎没有任何作用,当我尝试安装rgdal时,我仍然收到相同的错误消息。

我从这里去哪里?

1 个答案:

答案 0 :(得分:0)

我在Ubuntu 18.04上,但是我遇到了同样的问题(错误日志完全相同),对我来说,解决方案是将rgdal链接到由gdal构建的自定义项。我很幸运,由于其他原因,我已经从GDAL的源代码构建了/usr/local/gdal(git master)的副本。因此,要从源代码安装rgdal,我需要做的是:

  • wget https://cran.r-project.org/src/contrib/rgdal_1.3-4.tar.gz
  • sudo R CMD INSTALL --configure-args=--with-gdal-config=/usr/local/gdal/bin/gdal-config rgdal_1.3-4.tar.gz

如果走这条路,请确保您的gdal安装中所有投影数据都安装在了预期的位置,而我的不是,所以我不得不添加一个额外的步骤:

  • sudo cp -r /path/to/gdal-src-code/gdal/data/* /usr/local/gdal/share/gdal/