link项目如何在CentOS 6上成功安装sf包?

How to link proj to install succesfully the sf package on CentOS 6?

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

但是在到达 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

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

在我的例子中,有必要将 {sf} 的安装程序指向正确的 PROJ 实例。

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

您可能还会发现这个 CentOS 特定答案很有帮助: