如何链接项目以在 CentOS 6 上成功安装 sf 包?

Posted

技术标签:

【中文标题】如何链接项目以在 CentOS 6 上成功安装 sf 包?【英文标题】:How to link proj to install succesfully the sf package on CentOS 6? 【发布时间】:2021-03-26 09:25:07 【问题描述】:

我正在尝试为 R 安装 sf 软件包,遵循 CentOS 6 上的这个答案:

https://***.com/a/51369036/826500

但是当到达带有消息的proj 部分时它会失败:

proj.cpp:31:2: error: 'proj_context_set_search_paths' was not declared in this scope...

我在 sf 包 GitHub 问题页面寻求帮助,但 conda/GDAL/PROJ 设置似乎存在问题,可能与此问题有关:https://trac.osgeo.org/gdal/wiki/BuildingOnUnixGDAL25dev

尝试CXXFLAGS="-DPROJ_RENAME_SYMBOLS -O2" CFLAGS=$CXXFLAGS ./configure --prefix=/my/install/prefix --disable-static 时,出现错误:

CXXFLAGS=-DPROJ_RENAME_SYMBOLS -O2: command not found

由于这是我第一次进行这种安装,所以我不确定采取哪个方向来避免新的复杂性并成功安装软件包。

sf包安装的完整日志是这样的:

 install.packages('sf', repos='https://cran.rstudio.com/')
Installing package into ‘/home/relexteriores/R/x86_64-conda_cos6-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
--2020-12-15 12:05:03--  https://cran.rstudio.com/src/contrib/sf_0.9-6.tar.gz
Connecting to 168.176.239.40:8080... connected.
Proxy request sent, awaiting response... 200 OK
Length: 4160758 (4.0M) [application/x-gzip]
Saving to: “/tmp/RtmpcKdCbm/downloaded_packages/sf_0.9-6.tar.gz”

100%[==========================================================>] 4,160,758   5.03M/s   in 0.8s

2020-12-15 12:05:04 (5.03 MB/s) - “/tmp/RtmpcKdCbm/downloaded_packages/sf_0.9-6.tar.gz” saved [4160758/4160758]

* installing *source* package ‘sf’ ...
** package ‘sf’ successfully unpacked and MD5 sums checked
** using staged installation
configure: CC: /opt/miniconda2/envs/rsf/bin/x86_64-conda_cos6-linux-gnu-cc
configure: CXX: /opt/miniconda2/envs/rsf/bin/x86_64-conda_cos6-linux-gnu-c++
checking for gdal-config... /opt/miniconda2/envs/rsf/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 2.3.3
checking GDAL version >= 2.0.1... yes
checking for gcc... /opt/miniconda2/envs/rsf/bin/x86_64-conda_cos6-linux-gnu-cc
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 /opt/miniconda2/envs/rsf/bin/x86_64-conda_cos6-linux-gnu-cc accepts -g... yes
checking for /opt/miniconda2/envs/rsf/bin/x86_64-conda_cos6-linux-gnu-cc option to accept ISO C89... none needed
checking how to run the C preprocessor... /opt/miniconda2/envs/rsf/bin/x86_64-conda_cos6-linux-gnu-cpp
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: /opt/miniconda2/envs/rsf/share/gdal/pcs.csv readable... yes
checking GDAL: checking whether PROJ is available for linking:... yes
checking GDAL: checking whether PROJ is available fur running:... yes
configure: GDAL: 2.3.3
checking proj.h usability... yes
checking proj.h presence... yes
checking for proj.h... yes
checking PROJ: checking whether PROJ and sqlite3 are available for linking:... yes
checking for geos-config... /opt/miniconda2/envs/rsf/bin/geos-config
checking geos-config usability... yes
configure: GEOS: 3.7.1
checking GEOS version >= 3.4.0... yes
checking geos_c.h usability... yes
checking geos_c.h presence... yes
checking for geos_c.h... yes
checking geos: linking with -L/opt/miniconda2/envs/rsf/lib -lgeos_c... yes
configure: Package CPP flags:   -DHAVE_PROJ_H -I/opt/miniconda2/envs/rsf/include -I/opt/miniconda2/envs/rsf/include
configure: Package LIBS:  -L/opt/miniconda2/envs/rsf/lib -lgdal -lproj  -L/opt/miniconda2/envs/rsf/lib -lgdal -L/opt/miniconda2/envs/rsf/lib -lgeos_c
configure: creating ./config.status
config.status: creating src/Makevars
** libs
x86_64-conda_cos6-linux-gnu-c++ -std=gnu++11 -I"/opt/miniconda2/envs/rsf/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/opt/miniconda2/envs/rsf/include -I/opt/miniconda2/envs/rsf/include -I"/opt/miniconda2/envs/rsf/lib/R/library/Rcpp/include" -DNDEBUG -D_FORTIFY_SOURCE=2 -O2  -I/opt/miniconda2/envs/rsf/include -Wl,-rpath-link,/opt/miniconda2/envs/rsf/lib  -fpic  -fvisibility-inlines-hidden  -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/opt/miniconda2/envs/rsf/include -fdebug-prefix-map=/tmp/build/80754af9/r-base_1570124924484/work=/usr/local/src/conda/r-base-3.6.1 -fdebug-prefix-map=/opt/miniconda2/envs/rsf=/usr/local/src/conda-prefix  -c RcppExports.cpp -o RcppExports.o
x86_64-conda_cos6-linux-gnu-c++ -std=gnu++11 -I"/opt/miniconda2/envs/rsf/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/opt/miniconda2/envs/rsf/include -I/opt/miniconda2/envs/rsf/include -I"/opt/miniconda2/envs/rsf/lib/R/library/Rcpp/include" -DNDEBUG -D_FORTIFY_SOURCE=2 -O2  -I/opt/miniconda2/envs/rsf/include -Wl,-rpath-link,/opt/miniconda2/envs/rsf/lib  -fpic  -fvisibility-inlines-hidden  -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/opt/miniconda2/envs/rsf/include -fdebug-prefix-map=/tmp/build/80754af9/r-base_1570124924484/work=/usr/local/src/conda/r-base-3.6.1 -fdebug-prefix-map=/opt/miniconda2/envs/rsf=/usr/local/src/conda-prefix  -c bbox.cpp -o bbox.o
x86_64-conda_cos6-linux-gnu-c++ -std=gnu++11 -I"/opt/miniconda2/envs/rsf/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/opt/miniconda2/envs/rsf/include -I/opt/miniconda2/envs/rsf/include -I"/opt/miniconda2/envs/rsf/lib/R/library/Rcpp/include" -DNDEBUG -D_FORTIFY_SOURCE=2 -O2  -I/opt/miniconda2/envs/rsf/include -Wl,-rpath-link,/opt/miniconda2/envs/rsf/lib  -fpic  -fvisibility-inlines-hidden  -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/opt/miniconda2/envs/rsf/include -fdebug-prefix-map=/tmp/build/80754af9/r-base_1570124924484/work=/usr/local/src/conda/r-base-3.6.1 -fdebug-prefix-map=/opt/miniconda2/envs/rsf=/usr/local/src/conda-prefix  -c gdal.cpp -o gdal.o
x86_64-conda_cos6-linux-gnu-c++ -std=gnu++11 -I"/opt/miniconda2/envs/rsf/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/opt/miniconda2/envs/rsf/include -I/opt/miniconda2/envs/rsf/include -I"/opt/miniconda2/envs/rsf/lib/R/library/Rcpp/include" -DNDEBUG -D_FORTIFY_SOURCE=2 -O2  -I/opt/miniconda2/envs/rsf/include -Wl,-rpath-link,/opt/miniconda2/envs/rsf/lib  -fpic  -fvisibility-inlines-hidden  -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/opt/miniconda2/envs/rsf/include -fdebug-prefix-map=/tmp/build/80754af9/r-base_1570124924484/work=/usr/local/src/conda/r-base-3.6.1 -fdebug-prefix-map=/opt/miniconda2/envs/rsf=/usr/local/src/conda-prefix  -c gdal_geom.cpp -o gdal_geom.o
x86_64-conda_cos6-linux-gnu-c++ -std=gnu++11 -I"/opt/miniconda2/envs/rsf/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/opt/miniconda2/envs/rsf/include -I/opt/miniconda2/envs/rsf/include -I"/opt/miniconda2/envs/rsf/lib/R/library/Rcpp/include" -DNDEBUG -D_FORTIFY_SOURCE=2 -O2  -I/opt/miniconda2/envs/rsf/include -Wl,-rpath-link,/opt/miniconda2/envs/rsf/lib  -fpic  -fvisibility-inlines-hidden  -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/opt/miniconda2/envs/rsf/include -fdebug-prefix-map=/tmp/build/80754af9/r-base_1570124924484/work=/usr/local/src/conda/r-base-3.6.1 -fdebug-prefix-map=/opt/miniconda2/envs/rsf=/usr/local/src/conda-prefix  -c gdal_read.cpp -o gdal_read.o
x86_64-conda_cos6-linux-gnu-c++ -std=gnu++11 -I"/opt/miniconda2/envs/rsf/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/opt/miniconda2/envs/rsf/include -I/opt/miniconda2/envs/rsf/include -I"/opt/miniconda2/envs/rsf/lib/R/library/Rcpp/include" -DNDEBUG -D_FORTIFY_SOURCE=2 -O2  -I/opt/miniconda2/envs/rsf/include -Wl,-rpath-link,/opt/miniconda2/envs/rsf/lib  -fpic  -fvisibility-inlines-hidden  -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/opt/miniconda2/envs/rsf/include -fdebug-prefix-map=/tmp/build/80754af9/r-base_1570124924484/work=/usr/local/src/conda/r-base-3.6.1 -fdebug-prefix-map=/opt/miniconda2/envs/rsf=/usr/local/src/conda-prefix  -c gdal_utils.cpp -o gdal_utils.o
x86_64-conda_cos6-linux-gnu-c++ -std=gnu++11 -I"/opt/miniconda2/envs/rsf/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/opt/miniconda2/envs/rsf/include -I/opt/miniconda2/envs/rsf/include -I"/opt/miniconda2/envs/rsf/lib/R/library/Rcpp/include" -DNDEBUG -D_FORTIFY_SOURCE=2 -O2  -I/opt/miniconda2/envs/rsf/include -Wl,-rpath-link,/opt/miniconda2/envs/rsf/lib  -fpic  -fvisibility-inlines-hidden  -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/opt/miniconda2/envs/rsf/include -fdebug-prefix-map=/tmp/build/80754af9/r-base_1570124924484/work=/usr/local/src/conda/r-base-3.6.1 -fdebug-prefix-map=/opt/miniconda2/envs/rsf=/usr/local/src/conda-prefix  -c gdal_write.cpp -o gdal_write.o
x86_64-conda_cos6-linux-gnu-c++ -std=gnu++11 -I"/opt/miniconda2/envs/rsf/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/opt/miniconda2/envs/rsf/include -I/opt/miniconda2/envs/rsf/include -I"/opt/miniconda2/envs/rsf/lib/R/library/Rcpp/include" -DNDEBUG -D_FORTIFY_SOURCE=2 -O2  -I/opt/miniconda2/envs/rsf/include -Wl,-rpath-link,/opt/miniconda2/envs/rsf/lib  -fpic  -fvisibility-inlines-hidden  -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/opt/miniconda2/envs/rsf/include -fdebug-prefix-map=/tmp/build/80754af9/r-base_1570124924484/work=/usr/local/src/conda/r-base-3.6.1 -fdebug-prefix-map=/opt/miniconda2/envs/rsf=/usr/local/src/conda-prefix  -c geos.cpp -o geos.o
x86_64-conda_cos6-linux-gnu-c++ -std=gnu++11 -I"/opt/miniconda2/envs/rsf/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/opt/miniconda2/envs/rsf/include -I/opt/miniconda2/envs/rsf/include -I"/opt/miniconda2/envs/rsf/lib/R/library/Rcpp/include" -DNDEBUG -D_FORTIFY_SOURCE=2 -O2  -I/opt/miniconda2/envs/rsf/include -Wl,-rpath-link,/opt/miniconda2/envs/rsf/lib  -fpic  -fvisibility-inlines-hidden  -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/opt/miniconda2/envs/rsf/include -fdebug-prefix-map=/tmp/build/80754af9/r-base_1570124924484/work=/usr/local/src/conda/r-base-3.6.1 -fdebug-prefix-map=/opt/miniconda2/envs/rsf=/usr/local/src/conda-prefix  -c hex.cpp -o hex.o
x86_64-conda_cos6-linux-gnu-c++ -std=gnu++11 -I"/opt/miniconda2/envs/rsf/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/opt/miniconda2/envs/rsf/include -I/opt/miniconda2/envs/rsf/include -I"/opt/miniconda2/envs/rsf/lib/R/library/Rcpp/include" -DNDEBUG -D_FORTIFY_SOURCE=2 -O2  -I/opt/miniconda2/envs/rsf/include -Wl,-rpath-link,/opt/miniconda2/envs/rsf/lib  -fpic  -fvisibility-inlines-hidden  -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/opt/miniconda2/envs/rsf/include -fdebug-prefix-map=/tmp/build/80754af9/r-base_1570124924484/work=/usr/local/src/conda/r-base-3.6.1 -fdebug-prefix-map=/opt/miniconda2/envs/rsf=/usr/local/src/conda-prefix  -c ops.cpp -o ops.o
x86_64-conda_cos6-linux-gnu-c++ -std=gnu++11 -I"/opt/miniconda2/envs/rsf/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/opt/miniconda2/envs/rsf/include -I/opt/miniconda2/envs/rsf/include -I"/opt/miniconda2/envs/rsf/lib/R/library/Rcpp/include" -DNDEBUG -D_FORTIFY_SOURCE=2 -O2  -I/opt/miniconda2/envs/rsf/include -Wl,-rpath-link,/opt/miniconda2/envs/rsf/lib  -fpic  -fvisibility-inlines-hidden  -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/opt/miniconda2/envs/rsf/include -fdebug-prefix-map=/tmp/build/80754af9/r-base_1570124924484/work=/usr/local/src/conda/r-base-3.6.1 -fdebug-prefix-map=/opt/miniconda2/envs/rsf=/usr/local/src/conda-prefix  -c polygonize.cpp -o polygonize.o
x86_64-conda_cos6-linux-gnu-c++ -std=gnu++11 -I"/opt/miniconda2/envs/rsf/lib/R/include" -DNDEBUG -DHAVE_PROJ_H -I/opt/miniconda2/envs/rsf/include -I/opt/miniconda2/envs/rsf/include -I"/opt/miniconda2/envs/rsf/lib/R/library/Rcpp/include" -DNDEBUG -D_FORTIFY_SOURCE=2 -O2  -I/opt/miniconda2/envs/rsf/include -Wl,-rpath-link,/opt/miniconda2/envs/rsf/lib  -fpic  -fvisibility-inlines-hidden  -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/opt/miniconda2/envs/rsf/include -fdebug-prefix-map=/tmp/build/80754af9/r-base_1570124924484/work=/usr/local/src/conda/r-base-3.6.1 -fdebug-prefix-map=/opt/miniconda2/envs/rsf=/usr/local/src/conda-prefix  -c proj.cpp -o proj.o
proj.cpp: In function 'Rcpp::LogicalVector CPL_set_data_dir(std::__cxx11::string)':
proj.cpp:31:2: error: 'proj_context_set_search_paths' was not declared in this scope
  proj_context_set_search_paths(PJ_DEFAULT_CTX, 1, &cp);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
proj.cpp:31:2: note: suggested alternative: 'proj_context_destroy'
  proj_context_set_search_paths(PJ_DEFAULT_CTX, 1, &cp);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  proj_context_destroy
proj.cpp: In function 'Rcpp::LogicalVector CPL_use_proj4_init_rules(Rcpp::IntegerVector)':
proj.cpp:36:2: error: 'proj_context_use_proj4_init_rules' was not declared in this scope
  proj_context_use_proj4_init_rules(PJ_DEFAULT_CTX, v[0]);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
proj.cpp:36:2: note: suggested alternative: 'CPL_use_proj4_init_rules'
  proj_context_use_proj4_init_rules(PJ_DEFAULT_CTX, v[0]);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  CPL_use_proj4_init_rules
proj.cpp: In function 'Rcpp::List CPL_proj_is_valid(std::__cxx11::string)':
proj.cpp:50:2: error: 'proj_context_use_proj4_init_rules' was not declared in this scope
  proj_context_use_proj4_init_rules(PJ_DEFAULT_CTX, 1);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
proj.cpp:50:2: note: suggested alternative: 'CPL_use_proj4_init_rules'
  proj_context_use_proj4_init_rules(PJ_DEFAULT_CTX, 1);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  CPL_use_proj4_init_rules
proj.cpp: In function 'Rcpp::NumericMatrix CPL_proj_direct(Rcpp::CharacterVector, Rcpp::NumericMatrix, bool, bool, bool)':
proj.cpp:83:2: error: 'proj_context_use_proj4_init_rules' was not declared in this scope
  proj_context_use_proj4_init_rules(PJ_DEFAULT_CTX, 1);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
proj.cpp:83:2: note: suggested alternative: 'CPL_use_proj4_init_rules'
  proj_context_use_proj4_init_rules(PJ_DEFAULT_CTX, 1);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  CPL_use_proj4_init_rules
proj.cpp:88:7: error: 'proj_normalize_for_visualization' was not declared in this scope
   P = proj_normalize_for_visualization(PJ_DEFAULT_CTX, P);
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make: *** [/opt/miniconda2/envs/rsf/lib/R/etc/Makeconf:175: proj.o] Error 1
ERROR: compilation failed for package ‘sf’
* removing ‘/home/relexteriores/R/x86_64-conda_cos6-linux-gnu-library/3.6/sf’

The downloaded source packages are in
        ‘/tmp/RtmpcKdCbm/downloaded_packages’
Warning message:
In install.packages("sf", repos = "https://cran.rstudio.com/") :
  installation of package ‘sf’ had non-zero exit status

【问题讨论】:

【参考方案1】:

我在 ubuntu 上遇到过类似的问题;这些是由我的机器上的多个 PROJ 实例引起的(我从源代码安装了一个新版本,并且分发中包含一个古老的版本)。

就我而言,有必要将sf 的安装程序指向正确的PROJ 实例。

install.packages("sf", configure.args = "--with-proj-lib=/usr/local/lib/")

您也可能会发现这个 CentOS 特定答案很有帮助: installing sf package with libraries in non-standard locations

【讨论】:

谢谢。你的建议让我更进一步。它现在可以识别gdal 包,但不能识别proj 包。试过这个install.packages('sf', type = "source", configure.args='--with-gdal-config=/usr/local/gdal-2.4.3/bin/gdal-config --with-proj-lib=/usr/local/proj-5.2.0/lib') 并得到了checking GDAL: checking whether PROJ is available for linking:... yes checking GDAL: checking whether PROJ is available fur running:... ./gdal_proj: error while loading shared libraries: libgdal.so.20: cannot open shared object file: No such file or directory no 您可能必须重新编译 gdal 以确保它链接到正确的 PROJ。再三考虑:您可能希望从源代码安装 PROJ(首先)和 GDAL(之后)。你的版本已经过时了。尤其是高于 6.0.0 的 PROJ 是个好主意,因为该版本发生了重大变化 确实我在gdal 之前安装了proj 并在安装中指定了它的路径。我遵循了本指南thelinuxcluster.com/2019/12/17/compile-gdal-2-4-3-on-centos-7,但由于某种原因sf 无法识别proj 路径。 我尝试使用最新版本(GDAL 3.2.0 和 PROJ 7.2.0)并得到同样的错误:checking GDAL: checking whether PROJ is available for linking:... yes checking GDAL: checking whether PROJ is available fur running:... ./gdal_proj: error while loading shared libraries: libgdal.so.28: cannot open shared object file: No such file or directory no configure: error: OGRCoordinateTransformation() does not return a coord.trans: PROJ not available? ERROR: configuration failed for package ‘sf’

以上是关于如何链接项目以在 CentOS 6 上成功安装 sf 包?的主要内容,如果未能解决你的问题,请参考以下文章

如何在centOS 6上安装vnc-server

centos 6.9安装jira 7.2.6

如何配置 php 以在 CentOS 上启用 pdo 并包含 mysqli?

如何在 CentOS 6 上升级到 CouchDB 1.3.0 +?

如何在 Centos 6.5 上安装 python27-devel

在阿里云服务器centOS上部署自己的PHP项目,一次就会,十分钟部署速成