Hi everybody, I have just spent 3 hours trying to install sf on my machine without any success (I am just now switching to anaconda).
I have a Linux machine with a CentOS 7.15 distribution and with R 3.5.1 installed. I have tried to install sf but nothing, in the repository you can only find gdal 1.11 and not gdal 2.2. Then, this is what happened:
sf (any version, even the latest from github) this is what happens:> devtools::install_github("r-spatial/sf")
Downloading GitHub repo r-spatial/sf@master
from URL https://api.github.com/repos/r-spatial/sf/zipball/master
Installing sf
'/usr/lib64/R/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL \
'/tmp/Rtmpfet4gW/devtools4f76b2e442/r-spatial-sf-bafc5b5' \
--library='/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5' --install-tests
* installing *source* package ‘sf’ ...
configure: CC: gcc -m64 -std=gnu99
configure: CXX: g++ -m64 -std=gnu++11
checking for gdal-config... /usr/local/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 2.2.4
checking GDAL version >= 2.0.0... yes
checking for gcc... gcc -m64 -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 -m64 -std=gnu99 accepts -g... yes
checking for gcc -m64 -std=gnu99 option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -m64 -std=gnu99 -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/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/local/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: pkg-config proj exists, will use it
checking proj_api.h usability... yes
checking proj_api.h presence... yes
checking for proj_api.h... yes
configure: PROJ: 4.8.0
checking for pj_init_plus in -lproj... yes
/tmp/cc3nT6Mc.o: In function `main':
/tmp/Rtmpfet4gW/devtools4f76b2e442/r-spatial-sf-bafc5b5/proj_conf_test.c:20: undefined reference to `pj_ctx_fclose'
collect2: error: ld returned 1 exit status
./configure: line 3808: ./proj_conf_test: No such file or directory
checking PROJ: epsg found and readable... yes
/tmp/ccxztagi.o: In function `main':
/tmp/Rtmpfet4gW/devtools4f76b2e442/r-spatial-sf-bafc5b5/proj_conf_test.c:20: undefined reference to `pj_ctx_fclose'
collect2: error: ld returned 1 exit status
./configure: line 3867: ./proj_conf_test: No such file or directory
checking PROJ: conus found and readable... yes
checking for geos-config... /usr/local/bin/geos-config
checking geos-config usability... yes
configure: GEOS: 3.6.2
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/usr/local/lib -lgeos_c... yes
configure: Package CPP flags: -I/usr/local/include -I/usr/local/include
configure: Package LIBS: -lproj -L/usr/local/lib -lgdal -L/usr/local/lib -lgeos_c
configure: creating ./config.status
config.status: creating src/Makevars
** libs
g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/local/include -I/usr/local/include -I"/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c RcppExports.cpp -o RcppExports.o
g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/local/include -I/usr/local/include -I"/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c bbox.cpp -o bbox.o
g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/local/include -I/usr/local/include -I"/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c gdal.cpp -o gdal.o
g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/local/include -I/usr/local/include -I"/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c gdal_geom.cpp -o gdal_geom.o
g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/local/include -I/usr/local/include -I"/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c gdal_read.cpp -o gdal_read.o
g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/local/include -I/usr/local/include -I"/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c gdal_utils.cpp -o gdal_utils.o
g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/local/include -I/usr/local/include -I"/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c gdal_write.cpp -o gdal_write.o
gdal_write.cpp: In function ‘int CPL_write_ogr(Rcpp::List, Rcpp::CharacterVector, Rcpp::CharacterVector, Rcpp::CharacterVector, Rcpp::CharacterVector, Rcpp::CharacterVector, Rcpp::List, Rcpp::CharacterVector, bool, bool, bool, bool)’:
gdal_write.cpp:275:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (names.size() > i)
^
g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/local/include -I/usr/local/include -I"/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c geos.cpp -o geos.o
g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/local/include -I/usr/local/include -I"/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c hex.cpp -o hex.o
g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/local/include -I/usr/local/include -I"/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c proj.cpp -o proj.o
g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/local/include -I/usr/local/include -I"/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c raster2sf.cpp -o raster2sf.o
g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/local/include -I/usr/local/include -I"/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c sfg.cpp -o sfg.o
g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/local/include -I/usr/local/include -I"/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c signed_area.cpp -o signed_area.o
g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/local/include -I/usr/local/include -I"/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c stars.cpp -o stars.o
g++ -m64 -std=gnu++11 -I"/usr/include/R" -DNDEBUG -I/usr/local/include -I/usr/local/include -I"/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -c wkb.cpp -o wkb.o
g++ -m64 -std=gnu++11 -shared -L/usr/lib64/R/lib -Wl,-z,relro -o sf.so RcppExports.o bbox.o gdal.o gdal_geom.o gdal_read.o gdal_utils.o gdal_write.o geos.o hex.o proj.o raster2sf.o sfg.o signed_area.o stars.o wkb.o -lproj -L/usr/local/lib -lgdal -L/usr/local/lib -lgeos_c -L/usr/lib64/R/lib -lR
installing to /home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/sf/libs
** R
** data
** demo
** inst
** tests
** byte-compile and prepare package for lazy loading
in method for ‘dbWriteTable’ with signature ‘"PostgreSQLConnection","character","sf"’: no definition for class “PostgreSQLConnection”
in method for ‘dbDataType’ with signature ‘"PostgreSQLConnection","sf"’: no definition for class “PostgreSQLConnection”
in method for ‘coerce’ with signature ‘"Spatial","sf"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"Spatial","sfc"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"sf","Spatial"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"sfc","Spatial"’: no definition for class “Spatial”
in method for ‘coerce’ with signature ‘"XY","Spatial"’: no definition for class “Spatial”
** help
*** installing help indices
converting help for package ‘sf’
finding HTML links ... done
Ops html
aggregate.sf html
bgMap html
bind html
Rd warning: /tmp/Rtmpfet4gW/devtools4f76b2e442/r-spatial-sf-bafc5b5/man/bind.Rd:21: file link ‘rbind’ in package ‘base’ does not exist and so has been treated as a topic
Rd warning: /tmp/Rtmpfet4gW/devtools4f76b2e442/r-spatial-sf-bafc5b5/man/bind.Rd:36: file link ‘bind_cols’ in package ‘dplyr’ does not exist and so has been treated as a topic
coerce-methods html
dbDataType html
db_drivers html
extension_map html
gdal html
gdal_utils html
geos_binary_ops html
geos_binary_pred html
geos_combine html
geos_measures html
geos_query html
geos_unary html
internal html
is_driver_available html
is_driver_can html
is_geometry_column html
merge.sf html
plot html
Rd warning: /tmp/Rtmpfet4gW/devtools4f76b2e442/r-spatial-sf-bafc5b5/man/plot.Rd:86: file link ‘rainbow’ in package ‘grDevices’ does not exist and so has been treated as a topic
prefix_map html
rawToHex html
reexports html
Rd warning: /tmp/Rtmpfet4gW/devtools4f76b2e442/r-spatial-sf-bafc5b5/man/reexports.Rd:14: file link ‘%>%’ in package ‘magrittr’ does not exist and so has been treated as a topic
sf-deprecated html
sf html
sf_extSoftVersion html
sf_project html
sfc html
sgbp html
st html
st_agr html
st_as_binary html
st_as_grob html
st_as_sf html
st_as_sfc html
st_as_text html
st_bbox html
st_cast html
Rd warning: /tmp/Rtmpfet4gW/devtools4f76b2e442/r-spatial-sf-bafc5b5/man/st_cast.Rd:89: file link ‘aggregate’ in package ‘sf’ does not exist and so has been treated as a topic
Rd warning: /tmp/Rtmpfet4gW/devtools4f76b2e442/r-spatial-sf-bafc5b5/man/st_cast.Rd:89: file link ‘summarise’ in package ‘sf’ does not exist and so has been treated as a topic
st_cast_sfc_default html
st_collection_extract html
st_coordinates html
st_crop html
st_crs html
st_drivers html
st_geometry html
st_geometry_type html
st_graticule html
st_interpolate_aw html
st_is html
st_is_longlat html
st_jitter html
st_join html
Rd warning: /tmp/Rtmpfet4gW/devtools4f76b2e442/r-spatial-sf-bafc5b5/man/st_join.Rd:24: file link ‘left_join’ in package ‘dplyr’ does not exist and so has been treated as a topic
st_layers html
st_line_sample html
st_make_grid html
st_nearest_feature html
st_nearest_points html
st_precision html
st_read html
st_relate html
st_sample html
st_transform html
st_viewport html
st_write html
finding level-2 HTML links ... done
st_zm html
stars html
summary.sfc html
tibble html
tidyverse html
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error: package or namespace load failed for ‘sf’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/sf/libs/sf.so':
/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/sf/libs/sf.so: undefined symbol: _ZN10OGRFeature20GetFieldAsDoubleListEiPi
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/sf’
Installation failed: Command failed (1)
I would check whether
ldd /home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/sf/libs/sf.so | grep -i gdal
indeed shows that the shared library tries to link against shared libraries in /usr/local/lib. Your PROJ.5 is not being picked up by install, but that doesn't seem a problem.
Do you know if there is a way to avoid to have the installation directory deleted after the fail?
Hang on, it said
- removing ‘/home/felicma/R/x86_64-redhat-linux-gnu-library/3.5/sf’
so the .so I pointed to shouldn't be available after all.
The same with the latest version of sf from CRAN.
See the README section on Multiple GDAL, GEOS and/or PROJ versions on your system and #844 for the issue leading up to it.
Thanks for that information, actually I had two version of libproj. Unfortunately, I have the same issue now that I have removed all the libraries that were under /usr/local/lib (and no more duplicates on ldconfig -p). I still can't install the package.
If you provide me with a docker file that replicates your system, I can have a look at it.
Just want to document how I solved the undefined symbol: _ZN10OGRFeature20GetFieldAsDoubleListEiPi problem on my machine:
I did have two libgdal20.so binaries flying around, one probably from an old source install of GDAL that I forgot I did a year ago. I identified this by running
daniel@gin-nuest:/usr/share/proj$ ldconfig -p | grep gdal
libgdal.so.20 (libc6,x86-64) => /usr/local/lib/libgdal.so.20
libgdal.so.20 (libc6,x86-64) => /usr/lib/libgdal.so.20
libgdal.so (libc6,x86-64) => /usr/local/lib/libgdal.so
libgdal.so (libc6,x86-64) => /usr/lib/libgdal.so
So, two libgdal.so. After uninstalling GDAL (libgdal20) with apt and then running the same command again I got
daniel@gin-nuest:/usr/share/proj$ ldconfig -p | grep gdal
libgdal.so.20 (libc6,x86-64) => /usr/local/lib/libgdal.so.20
libgdal.so (libc6,x86-64) => /usr/local/lib/libgdal.so
So I manually removed the files (daniel@gin-nuest:/usr/local/lib$ sudo rm libgdal.*), updated the cache (rm /etc/ld.so.cache; ldconfig) and then installed GDAL from Ubuntu sources (not UbuntuGIS unstable). Installation of sf works again:
> library("sf")
Linking to GEOS 3.7.1, GDAL 2.2.3, PROJ 4.9.3
To add to @nuest workflow:
echo "/usr/local/lib" /etc/ld.so.conf.d/libgdal-x86_64.conf based on this SO post; this was what created the duplicated libgdal.so* in /usr/local/lib, as per @nuest post above.(base) bash-4.2$ ldconfig -p | grep gdal
libgdal.so.20 (libc6,x86-64) => /usr/local/lib/libgdal.so.20
libgdal.so.20 (libc6,x86-64) => /lib64/libgdal.so.20
libgdal.so.1 (libc6,x86-64) => /lib64/libgdal.so.1
libgdal.so (libc6,x86-64) => /usr/local/lib/libgdal.so
libgdal.so (libc6,x86-64) => /lib64/libgdal.so
so I went into /etc/ld.so.conf.d/, and did sudo rm libgdal-x86_64.conf
then sudo ldconfig to commit
my final ldconfig
(base) bash-4.2$ ldconfig -p | grep gdal
libgdal.so.20 (libc6,x86-64) => /lib64/libgdal.so.20
libgdal.so.1 (libc6,x86-64) => /lib64/libgdal.so.1
libgdal.so (libc6,x86-64) => /lib64/libgdal.so
install sf pointing to the gdal-config of choice; in the case of RHEL7, since we need to build GDAL >2.0 from source, point to path of compilation - e.g., install.packages('sf',configure.args='--with-gdal-config=/home/leungi/gdal-compile/bin/gdal-config'
then do the happy 🕺
Thank you both for the guidance.
Most helpful comment
Just want to document how I solved the
undefined symbol: _ZN10OGRFeature20GetFieldAsDoubleListEiPiproblem on my machine:I did have two
libgdal20.sobinaries flying around, one probably from an old source install of GDAL that I forgot I did a year ago. I identified this by runningSo, two
libgdal.so. After uninstalling GDAL (libgdal20) withaptand then running the same command again I gotSo I manually removed the files (
daniel@gin-nuest:/usr/local/lib$ sudo rm libgdal.*), updated the cache (rm /etc/ld.so.cache; ldconfig) and then installed GDAL from Ubuntu sources (not UbuntuGIS unstable). Installation ofsfworks again: