无法在Ubuntu14.04中安装rgdal(无法引用'pj_ctx_fclose')

6

我尝试使用configure.args安装rgdal,但没有成功。

已安装的gdal版本:

gdal-config --version
1.11.2

ogrinfo --version
GDAL 1.11.2, released 2015/02/10

发现了GDAL二进制工具:
ls /usr/bin | grep gdal
gdal2tiles.py
gdal2xyz.py
gdaladdo
gdal_auth.py
gdalbuildvrt
gdal_calc.py
gdalchksum.py
gdalcompare.py
gdal-config
gdal_contour
gdaldem
gdal_edit.py
gdalenhance
gdal_fillnodata.py
gdal_grid
gdalident.py
gdalimport.py
gdalinfo
gdallocationinfo
gdalmanage
gdal_merge.py
gdalmove.py
gdal_polygonize.py
gdal_proximity.py
gdal_rasterize
gdal_retile.py
gdalserver
gdal_sieve.py
gdalsrsinfo
gdaltindex
gdaltransform
gdal_translate
gdalwarp

发现项目头文件:

ls /usr/include | grep proj
libprojectM
libprojectM-qt
org_proj4_Projections.h
proj_api.h
projects.h

找到项目库文件:

ls /usr/lib | grep proj
libproj.a
libprojectM-qt.so
libprojectM-qt.so.1
libprojectM-qt.so.1.10
libprojectM.so
libprojectM.so.2
libprojectM.so.2.1.0
libproj.la
libproj.so
libproj.so.0
libproj.so.0.7.0

关于GDAL的已安装软件包:

dpkg -l | grep  gdal
ii  gdal-bin                                              1.11.2+dfsg-1~exp2~trusty                           amd64        Geospatial Data Abstraction Library - Utility programs
ii  libgdal-dev                                           1.11.2+dfsg-1~exp2~trusty                           amd64        Geospatial Data Abstraction Library - Development files
ii  libgdal1-dev                                          1.11.2+dfsg-1~exp2~trusty                           all          Geospatial Data Abstraction Library - Transitional package
ii  libgdal1h                                             1.11.2+dfsg-1~exp2~trusty                           amd64        Geospatial Data Abstraction Library
ii  python-gdal                                           1.11.2+dfsg-1~exp2~trusty                           amd64        Python bindings to the Geospatial Data Abstraction Library

dpkg -l | grep  proj
ii  libgeo-proj4-perl                                     1.05-1                                              amd64        PROJ.4 library for cartographic projections
ii  libproj-dev                                           4.8.0-2ubuntu2                                      amd64        Cartographic projection library (development files)
ii  libproj0                                              4.8.0-2ubuntu2                                      amd64        Cartographic projection library
ii  libprojectm-dev                                       2.1.0+dfsg-1build2                                  amd64        Advanced Milkdrop-compatible music visualization library - dev
ii  libprojectm-qt-dev                                    2.1.0+dfsg-1build2                                  amd64        projectM Qt4 (development files)
ii  libprojectm-qt1                                       2.1.0+dfsg-1build2                                  amd64        projectM Qt4 bindings
ii  libprojectm2                                          2.1.0+dfsg-1build2                                  amd64        Advanced Milkdrop-compatible music visualization library
ii  proj-bin                                              4.8.0-2ubuntu2                                      amd64        Cartographic projection library (tools)
ii  proj-data                                             4.8.0-2ubuntu2                                      amd64        Cartographic projection filter and library (datum package)
ii  projectm-data                                         2.1.0+dfsg-1build2                                  all          Advanced Milkdrop-compatible music visualization library - data
ii  xfwm4                                                 4.11.1-2ubuntu2                                     amd64        window manager of the Xfce project

install.packages('rgdal',type='source',
                  configure.args = paste('--with-gdal-config=/usr/bin/gdal-config',
                                         '--with-proj-lib=/usr/lib',
                                         '--with-proj-include=/usr/include') )
Installing package into ‘/home/wangchl/R/x86_64-pc-linux-gnu-library/3.2’
(as ‘lib’ is unspecified)
trying URL 'http://mirrors.ustc.edu.cn/CRAN/src/contrib/rgdal_0.9-2.tar.gz'
Content type 'application/gzip' length 1627386 bytes (1.6 MB)
==================================================
downloaded 1.6 MB

* installing *source* package ‘rgdal’ ...
** package ‘rgdal’ successfully unpacked and MD5 sums checked
configure: CC: gcc -std=gnu99
configure: CXX: g++
configure: rgdal: 0.9-2
checking for /usr/bin/svnversion... no
configure: svn revision: 526
configure: gdal-config set to /usr/bin/gdal-config
checking gdal-config exists... yes
checking gdal-config executable... yes
checking gdal-config usability... yes
configure: GDAL: 1.11.2
checking GDAL version >= 1.6.3... yes
checking GDAL version < 2... yes
checking for gcc... gcc -std=gnu99
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
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 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 gdal.h usability... yes
checking gdal.h presence... yes
checking for gdal.h... yes
checking gdal: linking with --libs only... yes
checking GDAL: /usr/share/gdal/1.11/pcs.csv readable... yes
checking proj_api.h usability... yes
checking proj_api.h presence... yes
checking for proj_api.h... yes
checking for pj_init_plus in -lproj... yes
configure: PROJ.4 version: > 4.8.0
/tmp/ccsGVxP9.o: In function `main':
/tmp/RtmpOqwz92/R.INSTALL23317ae38fc4/rgdal/proj_conf_test.c:20: undefined reference to `pj_ctx_fclose'
collect2: error: ld returned 1 exit status
./configure: line 3735: ./proj_conf_test: No such file or directory
checking PROJ.4: epsg found and readable... yes
/tmp/ccaNfCUo.o: In function `main':
/tmp/RtmpOqwz92/R.INSTALL23317ae38fc4/rgdal/proj_conf_test.c:20: undefined reference to `pj_ctx_fclose'
collect2: error: ld returned 1 exit status
./configure: line 3810: ./proj_conf_test: No such file or directory
checking PROJ.4: conus found and readable... yes
configure: Package CPP flags:  -I/usr/include/gdal -I/usr/include
configure: Package LIBS:  -L/usr/lib -lgdal -L/usr/lib -lproj
configure: creating ./config.status
config.status: creating src/Makevars
** libs
g++ -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I/usr/include  -I"/home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/sp/include"   -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -c OGR_write.cpp -o OGR_write.o
g++ -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I/usr/include  -I"/home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/sp/include"   -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -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/usr/include  -I"/home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/sp/include"   -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -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/usr/include  -I"/home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/sp/include"   -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -c local_stubs.c -o local_stubs.o
g++ -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I/usr/include  -I"/home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/sp/include"   -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -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/usr/include  -I"/home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/sp/include"   -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -c ogr_polygons.c -o ogr_polygons.o
g++ -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I/usr/include  -I"/home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/sp/include"   -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -c ogr_proj.cpp -o ogr_proj.o
g++ -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I/usr/include  -I"/home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/sp/include"   -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -c ogrdrivers.cpp -o ogrdrivers.o
g++ -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I/usr/include  -I"/home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/sp/include"   -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -c ogrsource.cpp -o ogrsource.o
g++ -I/usr/share/R/include -DNDEBUG -I/usr/include/gdal -I/usr/include  -I"/home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/sp/include"   -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -c projectit.cpp -o projectit.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o rgdal.so OGR_write.o gdal-bindings.o init.o local_stubs.o ogr_geom.o ogr_polygons.o ogr_proj.o ogrdrivers.o ogrsource.o projectit.o -L/usr/lib -lgdal -L/usr/lib -lproj -L/usr/lib/R/lib -lR
installing to /home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/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 in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/rgdal/libs/rgdal.so':
  /home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/rgdal/libs/rgdal.so: undefined symbol: pj_ctx_fgets
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/rgdal’
Warning in install.packages :
  installation of package ‘rgdal’ had non-zero exit status

编辑: 我已经尝试了install.packages('rgdal')而没有任何configure.args。我得到了同样的错误。 现在,我正在尝试使用编译的proj4 4.9.1安装rgdal,并将LD_LIBRARY_PATH导出到proj4 4.9.1。不幸的是,它再次失败了。 这是我的新script.sh:

export LD_LIBRARY_PATH=/home/wangchl/R-scripting/R-install/proj-4.9.1/ccc/lib:/usr/lib:$LD_LIBRARY_PATH

sudo R CMD REMOVE  rgdal

R CMD INSTALL rgdal_0.9-2.tar.gz --byte-compile --configure-args='--with-gdal-config=/usr/bin/gdal-config --with-proj-lib=/home/wangchl/R-scripting/R-install/proj-4.9.1/ccc/lib  --with-proj-include=/home/wangchl/R-scripting/R-install/proj-4.9.1/ccc/include  --with-proj-share=/home/wangchl/R-scripting/R-install/proj-4.9.1/ccc/share/proj'

一切都很好,但在测试时失败了:

installing to /home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/rgdal/libs
** R
** data
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/rgdal/libs/rgdal.so':
  /home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/rgdal/libs/rgdal.so: undefined symbol: pj_ctx_fgets
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/wangchl/R/x86_64-pc-linux-gnu-library/3.2/rgdal’

更新: 最终,我解决了这个问题。首先,通过apt-get删除proj4-4.8。

sudo apt-get remove libproj-dev

其次,将我编译的proj4-4.9库路径添加到一个新的配置文件(例如rgdal.conf)中,该文件位于“/etc/ld.so.conf.d/”路径下。
cd /etc/ld.so.conf.d
sudo touch rgdal.conf
echo 'the lib path of proj4-4.9' | sudo tee -a rgdal.conf 

然后,使用configure.args引用编译好的proj4-4.9库路径安装rgdal。

export LD_LIBRARY_PATH=the lib path of proj4-4.9:$LD_LIBRARY_PATH

sudo R CMD REMOVE  rgdal

R CMD INSTALL rgdal_0.9-2.tar.gz --byte-compile --configure-args='--with-gdal-config=/usr/bin/gdal-config --with-proj-lib=compiled path of proj4-4.9/lib  --with-proj-include=compiled path of proj4-4.9/include  --with-proj-share=compiled path of proj4-4.9/share/proj'

目前情况正常,但是我无法安装任何版本的rgdal和proj4-4.8以及默认的configure.args。我已经按照@Pascal的建议清理了proj4的文件,但是我不确定这个问题的确切原因。


1
这可能会有帮助:https://stat.ethz.ch/pipermail/r-sig-geo/2012-May/014973.html。如果您安装了多个版本的proj,则可能会遇到问题。 - user3710546
感谢 @Pascal 的慷慨帮助。你能提供一些解决方案吗? - seifer_08ms
1
我建议先删除proj.4 4.8,并检查是否有任何文件(proj,libproj...)仍留在/usr/bin/usr/include/usr/lib,以及/usr/local/bin/usr/local/include/usr/local/lib。然后进行编译(make),安装(make install)和卸载(make uninstall)proj.4 4.9。最后使用apt-get安装proj.4 4.8。 - user3710546
1
我不这么认为。我的当前设置是Ubuntu 14.10,R版本为3.2.0,proj.4版本为4.8.0-5,rgdal_0.9-2。 并且它可以正常工作。 - user3710546
最终,我解决了这个问题。首先,通过apt-get删除proj4-4.8。其次,将我编译的proj4-4.9库路径添加到新的conf文件(例如rgdal.conf)中,并将其移动到'/etc/ld.so.conf.d/'路径下。然后,使用configure.args安装rgdal,引用proj4-4.9的路径。现在,一切都很好。但是我无法使用proj4-4.8和默认的configure.args安装较旧版本的rgdal。 - seifer_08ms
显示剩余3条评论
2个回答

3
你是否已经安装了libgdal-devlibproj-dev?请在终端中执行以下命令:
sudo apt-get update && sudo apt-get install libgdal-dev libproj-dev

然后在R中尝试重新安装rgdal

我可以通过命令 'dpkg -l | grep gdal' 和 'dpkg -l | grep proj' 来确认这些。我的问题中列出了已安装的软件包。 - seifer_08ms
是的,我的错,我在那个代码块中向下滚动并查看错误。我注意到在我的系统上安装了 v1.10.1 的 gdal(14.04); 您使用的 v1.11.x 是否会导致问题? - Phil
1
很可能是proj.4版本之间的冲突,正如此处所述:https://stat.ethz.ch/pipermail/r-sig-geo/2012-May/014973.html - user3710546
我之前编译过proj4 4.9,但不确定是否已完全清除。我只删除了proj4 4.9的lib文件和头文件,并通过apt-get安装了4.8版本。编译后的文件仍留在其路径中,不应在系统端激活。您能给我一些建议来解决版本问题吗? - seifer_08ms
你尝试重新安装 rdal 了吗? - user3710546
显示剩余4条评论

2

最终,我解决了这个问题。首先,通过apt-get删除proj4-4.8。

sudo apt-get remove libproj-dev

其次,将我编译的 proj4-4.9 库路径添加到新的配置文件中(例如 rgdal.conf),位于“/etc/ld.so.conf.d/”路径下。
cd /etc/ld.so.conf.d
sudo touch rgdal.conf
echo 'the lib path of proj4-4.9' | sudo tee -a rgdal.conf 

然后,使用configure.args指向编译好的proj4-4.9库路径来安装rgdal。

export LD_LIBRARY_PATH=the lib path of proj4-4.9:$LD_LIBRARY_PATH

sudo R CMD REMOVE  rgdal

R CMD INSTALL rgdal_0.9-2.tar.gz --byte-compile --configure-args='--with-gdal-config=/usr/bin/gdal-config --with-proj-lib=compiled path of proj4-4.9/lib  --with-proj-include=compiled path of proj4-4.9/include  --with-proj-share=compiled path of proj4-4.9/share/proj'

现在一切都好。但我无法安装任何版本的rgdal,包括proj4-4.8和默认的configure.args。我已经按照@Pascal的建议清理了proj4的文件。因此,我不确定这个问题的确切原因。


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