无法在ubuntu 14.04中安装rgdal(未定义以引用' pj_ctx_fclose')

时间:2015-05-19 08:36:07

标签: r gdal rgdal proj4

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

已安装的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

找到了proj头文件:

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

找到了proj lib文件:

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(&#39; rgdal&#39;)而没有任何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 lib路径添加到&#39; /etc/ld.so.conf.d /&#39;路径下的新conf文件(例如rgdal.conf)中。

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安装rgdal,引用proj4-4.9的已编译lib路径。

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'

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

2 个答案:

答案 0 :(得分:3)

您是否安装了libgdal-devlibproj-dev

在终端:

sudo apt-get update && sudo apt-get install libgdal-dev libproj-dev

然后在R中尝试再次安装rgdal

答案 1 :(得分:2)

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

sudo apt-get remove libproj-dev

其次,将我编译的proj4-4.9 lib路径添加到'/etc/ld.so.conf.d /'路径下的新conf文件(例如rgdal.conf)中。

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安装rgdal,引用proj4-4.9的已编译的lib路径。

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'

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