r - 尽管C++ 11可用,但正在更新R.3.5.1 C++ 11依赖关系中的Rgdal ...

标签 r c++11 gdal rgdal

当我从3.4.4更新到3.5.1后,通过从源代码进行编译来更新(或至少尝试)rgdal软件包时,我遇到了一个一切都进行得很好的奇怪问题,但是由于“ undefined symbol ”错误:

** 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 '/usr/local/lib/R/site-library/rgdal/libs/rgdal.so':
  /usr/local/lib/R/site-library/rgdal/libs/rgdal.so: undefined symbol: _ZNK10OGRFeature16GetFieldAsDoubleEi
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/usr/local/lib/R/site-library/rgdal’
* restoring previous ‘/usr/local/lib/R/site-library/rgdal’

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

当运行echo _ZNK10OGRFeature16GetFieldAsDoubleEi | c++filt时,我得到的输出OGRFeature::GetFieldAsDouble(int) const并不能帮助我。我已经从https://trac.osgeo.org/gdal/wiki/DownloadSource安装了GDAL,如CRAN软件包站点上所建议的那样,该文件显示我已经安装了GDAL 2.3.1。

奇怪的是,更新失败了,因为已经安装了该软件包,因此应该已经满足依赖关系。热烈欢迎您提出任何有关如何解决此问题的指示。

由于过去几周没有任何建议,我决定卸载rgdal,然后重新安装。有趣的是,现在我声称我的系统(Ubuntu 16.04.5 LTS)不支持C++ 11,尽管检查表明它在那里(C++11 support available):
* 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... yes
configure: svn revision: 766
checking for gdal-config... /usr/local/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 2.3.1
checking C++11 support for GDAL >= 2.3.0... yes
checking GDAL version >= 1.11.4... yes
checking gdal: linking with --libs only... no
checking gdal: linking with --libs and --dep-libs... no
In file included from /usr/local/include/gdal.h:45:0,
                 from gdal_test.cc:1:
/usr/local/include/cpl_port.h:187:6: error: #error Must have C++11 or newer.
 #    error Must have C++11 or newer.
      ^
In file included from /usr/local/include/gdal.h:49:0,
                 from gdal_test.cc:1:
/usr/local/include/cpl_minixml.h:202:47: error: expected template-name before '<' token
 class CPLXMLTreeCloser: public std::unique_ptr<CPLXMLNode, CPLXMLTreeCloserDeleter>
                                               ^
/usr/local/include/cpl_minixml.h:202:47: error: expected '{' before '<' token
/usr/local/include/cpl_minixml.h:202:47: error: expected unqualified-id before '<' token
In file included from /usr/local/include/ogr_api.h:45:0,
                 from /usr/local/include/gdal.h:50,
                 from gdal_test.cc:1:
/usr/local/include/ogr_core.h:79:28: error: expected '}' before end of line
/usr/local/include/ogr_core.h:79:28: error: expected declaration before end of line
In file included from /usr/local/include/gdal.h:45:0,
                 from gdal_test.cc:1:
/usr/local/include/cpl_port.h:187:6: error: #error Must have C++11 or newer.
 #    error Must have C++11 or newer.
      ^
In file included from /usr/local/include/gdal.h:49:0,
                 from gdal_test.cc:1:
/usr/local/include/cpl_minixml.h:202:47: error: expected template-name before '<' token
 class CPLXMLTreeCloser: public std::unique_ptr<CPLXMLNode, CPLXMLTreeCloserDeleter>
                                               ^
/usr/local/include/cpl_minixml.h:202:47: error: expected '{' before '<' token
/usr/local/include/cpl_minixml.h:202:47: error: expected unqualified-id before '<' token
In file included from /usr/local/include/ogr_api.h:45:0,
                 from /usr/local/include/gdal.h:50,
                 from gdal_test.cc:1:
/usr/local/include/ogr_core.h:79:28: error: expected '}' before end of line
/usr/local/include/ogr_core.h:79:28: error: expected declaration before end of line
configure: Install failure: compilation and/or linkage problems.
configure: error: GDALAllRegister not found in libgdal.
ERROR: configuration failed for package ‘rgdal’
* removing ‘/usr/local/lib/R/site-library/rgdal’

我的devtools::session_info()是以下内容:
Session info ------------------------------------------------------------------
 setting  value
 version  R version 3.5.1 (2018-07-02)
 system   x86_64, linux-gnu
 ui       X11
 language en_US:en
 collate  en_US.UTF-8
 tz       Europe/Brussels
 date     2018-07-28

Packages ----------------------------------------------------------------------
 package   * version date       source
 base      * 3.5.1   2018-07-03 local
 compiler    3.5.1   2018-07-03 local
 datasets  * 3.5.1   2018-07-03 local
 devtools  * 1.13.6  2018-06-27 CRAN (R 3.5.1)
 digest      0.6.15  2018-01-28 CRAN (R 3.5.1)
 graphics  * 3.5.1   2018-07-03 local
 grDevices * 3.5.1   2018-07-03 local
 memoise     1.1.0   2017-04-21 CRAN (R 3.5.1)
 methods   * 3.5.1   2018-07-03 local
 stats     * 3.5.1   2018-07-03 local
 tools       3.5.1   2018-07-03 local
 utils     * 3.5.1   2018-07-03 local
 withr       2.1.2   2018-03-15 CRAN (R 3.5.1)

最佳答案

就我而言,解决方案是更新我的~/.R/Makevars配置。

  CC=clang
  CXX=clang++
  PKG_CFLAGS= -g -O2

我在我的CXX定义中添加了 -std = gnu++ 11
  CC=clang
  CXX=clang++ -std=gnu++11
  PKG_CFLAGS= -g -O2

在此之后,不再出现编译问题和相关错误(至少到目前为止我的测试中没有)

推理

上面引出了一个问题-为什么?以我的经验,使用rgdal进行的新R 3.5.1安装不会出现编译错误,而从3.4.4进行升级会出现编译错误。我的感觉是R和rgdal软件包配置之间存在相互作用,导致C++ 11编译标志未激活。 rgdal需要并使用C++ 11功能。请参阅Makevar-下面的概述。

引文:
  • R Installation and Administration
  • R Using Makevars
  • How do I enable C++11 in gcc?

  • 编译示例:

    Makevars中没有-std=gnu++11标志[错误]
    > install.packages("rgdal")
    --2018-08-10 21:31:58--  https://cran.rstudio.com/src/contrib/rgdal_1.3-4.tar.gz
    Resolving cran.rstudio.com (cran.rstudio.com)... 52.84.17.191
    Connecting to cran.rstudio.com (cran.rstudio.com)|52.84.17.191|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1664774 (1.6M) [application/x-gzip]
    Saving to: ‘/var/folders/md/03gdc4c14z18kbqwpfh4jdfc0000gr/T//RtmpidZNr4/downloaded_packages/rgdal_1.3-4.tar.gz’
    
    /var/folders/md/03gdc4c14z18kbqwpfh4jd 100%[============================================================================>]   1.59M  --.-KB/s    in 0.04s
    
    2018-08-10 21:31:58 (35.6 MB/s) - ‘/var/folders/md/03gdc4c14z18kbqwpfh4jdfc0000gr/T//RtmpidZNr4/downloaded_packages/rgdal_1.3-4.tar.gz’ saved [1664774/1664774]
    
    * installing *source* package ‘rgdal’ ...
    ** package ‘rgdal’ successfully unpacked and MD5 sums checked
    configure: R_HOME: /Users/***/.Renv/versions/3.5.1/lib/R
    configure: CC: clang
    configure: CXX: clang++
    configure: C++11 support available
    configure: rgdal: 1.3-4
    checking for /usr/bin/svnversion... yes
    configure: svn revision: 766
    checking for gdal-config... /usr/local/opt/gdal2/bin/gdal-config
    checking gdal-config usability... yes
    configure: GDAL: 2.3.1
    checking C++11 support for GDAL >= 2.3.0... yes
    checking GDAL version >= 1.11.4... yes
    checking gdal: linking with --libs only... no
    checking gdal: linking with --libs and --dep-libs... no
    In file included from gdal_test.cc:1:
    In file included from /usr/local/Cellar/gdal2/2.3.1/include/gdal.h:45:
    /usr/local/Cellar/gdal2/2.3.1/include/cpl_port.h:187:6: error: Must have C++11 or newer.
    #    error Must have C++11 or newer.
         ^
    1 error generated.
    In file included from gdal_test.cc:1:
    In file included from /usr/local/Cellar/gdal2/2.3.1/include/gdal.h:45:
    /usr/local/Cellar/gdal2/2.3.1/include/cpl_port.h:187:6: error: Must have C++11 or newer.
    #    error Must have C++11 or newer.
         ^
    1 error generated.
    configure: Install failure: compilation and/or linkage problems.
    configure: error: GDALAllRegister not found in libgdal.
    ERROR: configuration failed for package ‘rgdal’
    * removing ‘/Users/***/.Renv/versions/3.5.1/lib/R/library/rgdal’
    
    The downloaded source packages are in
        ‘/private/var/folders/md/03gdc4c14z18kbqwpfh4jdfc0000gr/T/RtmpidZNr4/downloaded_packages’
    Updating HTML index of packages in '.Library'
    Making 'packages.html' ... done
    Warning message:
    In install.packages("rgdal") :
      installation of package ‘rgdal’ had non-zero exit status
    

    在Makevars中添加了-std=gnu++11
    > install.packages("rgdal")
    --2018-08-10 21:34:20--  https://cran.rstudio.com/src/contrib/rgdal_1.3-4.tar.gz
    Resolving cran.rstudio.com (cran.rstudio.com)... 52.84.17.191
    Connecting to cran.rstudio.com (cran.rstudio.com)|52.84.17.191|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1664774 (1.6M) [application/x-gzip]
    Saving to: ‘/var/folders/md/03gdc4c14z18kbqwpfh4jdfc0000gr/T//RtmpidZNr4/downloaded_packages/rgdal_1.3-4.tar.gz’
    
    /var/folders/md/03gdc4c14z18kbqwpfh4jd 100%[============================================================================>]   1.59M  --.-KB/s    in 0.04s
    
    2018-08-10 21:34:20 (43.5 MB/s) - ‘/var/folders/md/03gdc4c14z18kbqwpfh4jdfc0000gr/T//RtmpidZNr4/downloaded_packages/rgdal_1.3-4.tar.gz’ saved [1664774/1664774]
    
    * installing *source* package ‘rgdal’ ...
    ** package ‘rgdal’ successfully unpacked and MD5 sums checked
    configure: R_HOME: /Users/***/.Renv/versions/3.5.1/lib/R
    configure: CC: clang
    configure: CXX: clang++ -std=gnu++11
    configure: C++11 support available
    configure: rgdal: 1.3-4
    checking for /usr/bin/svnversion... yes
    configure: svn revision: 766
    checking for gdal-config... /usr/local/opt/gdal2/bin/gdal-config
    checking gdal-config usability... yes
    configure: GDAL: 2.3.1
    checking C++11 support for GDAL >= 2.3.0... yes
    checking GDAL version >= 1.11.4... yes
    checking gdal: linking with --libs only... yes
    checking GDAL: /usr/local/Cellar/gdal2/2.3.1/share/gdal/pcs.csv readable... yes
    configure: pkg-config proj exists, will use it
    configure: PROJ version: 5.1.0
    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/local/Cellar/gdal2/2.3.1/include -I/usr/local/Cellar/proj/5.1.0/include
    configure: Package LIBS:  -L/usr/local/Cellar/gdal2/2.3.1/lib -lgdal -lproj
    configure: creating ./config.status
    config.status: creating src/Makevars
    ** libs
    g++ -std=gnu++11 -I"/Users/***/.Renv/versions/3.5.1/lib/R/include" -DNDEBUG -I/usr/local/Cellar/gdal2/2.3.1/include -I/usr/local/Cellar/proj/5.1.0/include -I"/Users/***/.Renv/versions/3.5.1/lib/R/library/sp/include" -I/usr/local/opt/gdal2/include -I/usr/local/opt/liblas-gdal2/include -I/usr/local/opt/laszip@2.2/include -I/usr/local/opt/bzip2/include -I/usr/local/opt/zlib/include  -g -O2 -stdlib=libc++ -std=c++11 -fPIC  -g -O2 -c OGR_write.cpp -o OGR_write.o
    g++ -std=gnu++11 -I"/Users/***/.Renv/versions/3.5.1/lib/R/include" -DNDEBUG -I/usr/local/Cellar/gdal2/2.3.1/include -I/usr/local/Cellar/proj/5.1.0/include -I"/Users/***/.Renv/versions/3.5.1/lib/R/library/sp/include" -I/usr/local/opt/gdal2/include -I/usr/local/opt/liblas-gdal2/include -I/usr/local/opt/laszip@2.2/include -I/usr/local/opt/bzip2/include -I/usr/local/opt/zlib/include  -g -O2 -stdlib=libc++ -std=c++11 -fPIC  -g -O2 -c gdal-bindings.cpp -o gdal-bindings.o
    clang -I"/Users/***/.Renv/versions/3.5.1/lib/R/include" -DNDEBUG -I/usr/local/Cellar/gdal2/2.3.1/include -I/usr/local/Cellar/proj/5.1.0/include -I"/Users/***/.Renv/versions/3.5.1/lib/R/library/sp/include" -I/usr/local/opt/gdal2/include -I/usr/local/opt/liblas-gdal2/include -I/usr/local/opt/laszip@2.2/include -I/usr/local/opt/bzip2/include -I/usr/local/opt/zlib/include  -g -O2 -fPIC  -g -O2  -c init.c -o init.o
    clang -I"/Users/***/.Renv/versions/3.5.1/lib/R/include" -DNDEBUG -I/usr/local/Cellar/gdal2/2.3.1/include -I/usr/local/Cellar/proj/5.1.0/include -I"/Users/***/.Renv/versions/3.5.1/lib/R/library/sp/include" -I/usr/local/opt/gdal2/include -I/usr/local/opt/liblas-gdal2/include -I/usr/local/opt/laszip@2.2/include -I/usr/local/opt/bzip2/include -I/usr/local/opt/zlib/include  -g -O2 -fPIC  -g -O2  -c inverser.c -o inverser.o
    clang -I"/Users/***/.Renv/versions/3.5.1/lib/R/include" -DNDEBUG -I/usr/local/Cellar/gdal2/2.3.1/include -I/usr/local/Cellar/proj/5.1.0/include -I"/Users/***/.Renv/versions/3.5.1/lib/R/library/sp/include" -I/usr/local/opt/gdal2/include -I/usr/local/opt/liblas-gdal2/include -I/usr/local/opt/laszip@2.2/include -I/usr/local/opt/bzip2/include -I/usr/local/opt/zlib/include  -g -O2 -fPIC  -g -O2  -c local_stubs.c -o local_stubs.o
    g++ -std=gnu++11 -I"/Users/***/.Renv/versions/3.5.1/lib/R/include" -DNDEBUG -I/usr/local/Cellar/gdal2/2.3.1/include -I/usr/local/Cellar/proj/5.1.0/include -I"/Users/***/.Renv/versions/3.5.1/lib/R/library/sp/include" -I/usr/local/opt/gdal2/include -I/usr/local/opt/liblas-gdal2/include -I/usr/local/opt/laszip@2.2/include -I/usr/local/opt/bzip2/include -I/usr/local/opt/zlib/include  -g -O2 -stdlib=libc++ -std=c++11 -fPIC  -g -O2 -c ogr_geom.cpp -o ogr_geom.o
    clang -I"/Users/***/.Renv/versions/3.5.1/lib/R/include" -DNDEBUG -I/usr/local/Cellar/gdal2/2.3.1/include -I/usr/local/Cellar/proj/5.1.0/include -I"/Users/***/.Renv/versions/3.5.1/lib/R/library/sp/include" -I/usr/local/opt/gdal2/include -I/usr/local/opt/liblas-gdal2/include -I/usr/local/opt/laszip@2.2/include -I/usr/local/opt/bzip2/include -I/usr/local/opt/zlib/include  -g -O2 -fPIC  -g -O2  -c ogr_polygons.c -o ogr_polygons.o
    g++ -std=gnu++11 -I"/Users/***/.Renv/versions/3.5.1/lib/R/include" -DNDEBUG -I/usr/local/Cellar/gdal2/2.3.1/include -I/usr/local/Cellar/proj/5.1.0/include -I"/Users/***/.Renv/versions/3.5.1/lib/R/library/sp/include" -I/usr/local/opt/gdal2/include -I/usr/local/opt/liblas-gdal2/include -I/usr/local/opt/laszip@2.2/include -I/usr/local/opt/bzip2/include -I/usr/local/opt/zlib/include  -g -O2 -stdlib=libc++ -std=c++11 -fPIC  -g -O2 -c ogr_proj.cpp -o ogr_proj.o
    g++ -std=gnu++11 -I"/Users/***/.Renv/versions/3.5.1/lib/R/include" -DNDEBUG -I/usr/local/Cellar/gdal2/2.3.1/include -I/usr/local/Cellar/proj/5.1.0/include -I"/Users/***/.Renv/versions/3.5.1/lib/R/library/sp/include" -I/usr/local/opt/gdal2/include -I/usr/local/opt/liblas-gdal2/include -I/usr/local/opt/laszip@2.2/include -I/usr/local/opt/bzip2/include -I/usr/local/opt/zlib/include  -g -O2 -stdlib=libc++ -std=c++11 -fPIC  -g -O2 -c ogrdrivers.cpp -o ogrdrivers.o
    g++ -std=gnu++11 -I"/Users/***/.Renv/versions/3.5.1/lib/R/include" -DNDEBUG -I/usr/local/Cellar/gdal2/2.3.1/include -I/usr/local/Cellar/proj/5.1.0/include -I"/Users/***/.Renv/versions/3.5.1/lib/R/library/sp/include" -I/usr/local/opt/gdal2/include -I/usr/local/opt/liblas-gdal2/include -I/usr/local/opt/laszip@2.2/include -I/usr/local/opt/bzip2/include -I/usr/local/opt/zlib/include  -g -O2 -stdlib=libc++ -std=c++11 -fPIC  -g -O2 -c ogrsource.cpp -o ogrsource.o
    g++ -std=gnu++11 -I"/Users/***/.Renv/versions/3.5.1/lib/R/include" -DNDEBUG -I/usr/local/Cellar/gdal2/2.3.1/include -I/usr/local/Cellar/proj/5.1.0/include -I"/Users/***/.Renv/versions/3.5.1/lib/R/library/sp/include" -I/usr/local/opt/gdal2/include -I/usr/local/opt/liblas-gdal2/include -I/usr/local/opt/laszip@2.2/include -I/usr/local/opt/bzip2/include -I/usr/local/opt/zlib/include  -g -O2 -stdlib=libc++ -std=c++11 -fPIC  -g -O2 -c projectit.cpp -o projectit.o
    g++ -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Users/***/.Renv/versions/3.5.1/lib/R/lib -L/usr/local/opt/gdal2/lib -L/usr/local/opt/liblas-gdal2/lib -L/usr/local/opt/laszip@2.2/lib -L/usr/local/opt/bzip2/lib -L/usr/local/opt/zlib/lib -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/local/Cellar/gdal2/2.3.1/lib -lgdal -lproj -L/Users/***/.Renv/versions/3.5.1/lib/R/lib -lR -Wl,-framework -Wl,CoreFoundation
    installing to /Users/***/.Renv/versions/3.5.1/lib/R/library/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
    * DONE (rgdal)
    
    The downloaded source packages are in
        ‘/private/var/folders/md/03gdc4c14z18kbqwpfh4jdfc0000gr/T/RtmpidZNr4/downloaded_packages’
    Updating HTML index of packages in '.Library'
    Making 'packages.html' ... done
    

    MakeVars-概述:

    Makevars是一个覆盖R生成的默认makefile的makefile(位于file.path(R.home(“etc”),“Makeconf”))。这样一来,您就可以利用R的默认行为,同时可以设置所需的标志。这些是最常用的标志:
  • PKG_LIBS
    链接器标志。常见用法是PKG_LIBS = $(BLAS_LIBS)。这使您可以使用与R.相同的BLAS库。
  • PKG_CFLAGS PKG_CXXFLAGS
    C和C++标志。最常用于通过-D设置定义指令。

  • PKG_CPPFLAGS
    预处理器标志(不是C++标志!)。最常用的设置包括带有-I的目录。在Description的LinkingTo字段中列出的所有软件包都将自动包括在内-您无需显式添加它。

    希望以上内容能为您指明解决方案的方向。

    关于r - 尽管C++ 11可用,但正在更新R.3.5.1 C++ 11依赖关系中的Rgdal ...,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51566741/

    相关文章:

    c++11 - <random> 获取 rng-engine 的内部状态

    python - GDAL 错误 : command 'cc' failed with exit status 1

    c - 通过 GDAL GDALAutoCreateWarpedVRT 在 C 中重新投影

    r - 如何过滤日期和时间?

    mysql - RODBC 错误 - ODBC 连接失败 - 无法使用我的 Mac 连接到 MySQL(小牛)

    r - 如何在R中合并表?

    c++ - std::forward_list - 如何在末尾插入元素

    c++11 foreach 语法和自定义迭代器

    python - python 中的 fiona 导入问题

    r - R:两个输出窗口?