Search code examples
rcondacentos6r-sfproj

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


I'm trying to install the sf package for R, following this answer on CentOS 6:

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

But it fails when reaching the proj part with the message:

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

I asked for help in the sf package GitHub Issues page but it seems there is a problem with the conda/GDAL/PROJ setup, maybe related to this issue: https://trac.osgeo.org/gdal/wiki/BuildingOnUnixGDAL25dev

When trying CXXFLAGS="-DPROJ_RENAME_SYMBOLS -O2" CFLAGS=$CXXFLAGS ./configure --prefix=/my/install/prefix --disable-static, I get an error:

CXXFLAGS=-DPROJ_RENAME_SYMBOLS -O2: command not found

As this is my first time with this kind of installation I'm not really sure which direction take in order to avoid new complexities and get the package installed succesfully.

The complete log of the sf package installation is this:

 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

Solution

  • I have had similar issues on ubuntu; these were caused by multiple instances of PROJ on my machine (I have installed a new version from source, and there was an ancient one included with the distribution).

    In my case it was necessary to point the installer of {sf} to the correct PROJ instance.

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

    You may also find helpful this CentOS specific answer: installing sf package with libraries in non-standard locations