I need to install sf
package for R in CentOS 7.
The repo versions of gdal
and proj
are less than the required for the package, so I installed them from source.
Even linking those libraries I always get the same error:
configure: GDAL: 3.2.0
checking proj.h usability... no
checking proj.h presence... no
checking for proj.h... no
checking proj_api.h usability... no
checking proj_api.h presence... no
checking for proj_api.h... no
configure: error: proj_api.h not found in standard or given locations.
ERROR: configuration failed for package ‘sf’
I have tried different commands, and from diferent sources (CRAN, GitHub, locally) and always get the same error.
For example:
install_github("r-spatial/sf", configure.args="--with-gdal-config=/usr/local/gdal-3.2.0/bin/gdal-config --with-proj-lib=/usr/local/proj-7.2.0/lib --with-proj-include=/usr/local/proj-7.2.0/include")
proj_api.h
is present at the specified path:
locate proj_api.h
/usr/local/proj-7.2.0/include/proj_api.h
2
Answers
The solution was really simple. I just copied the files in
/usr/local/proj-7.2.0/include
to/usr/local/include
and the files in/usr/local/proj-7.2.0/lib
to/usr/local/lib
.Then I added a
.conf
file in/etc/ld.so.conf.d
with the path to/usr/local/proj-7.2.0/lib
and ransudo ldconfig
.It seems that while other packages recognize
proj
in custom locations,sf
doesn't. Particulary, this part does nothing"--with-proj-lib=/usr/local/proj-7.2.0/lib", "--with-proj-include=/usr/local/proj-7.2.0/include"
.The command line to install
sf
wasinstall.packages("sf", configure.args="--with-gdal-config=/usr/local/gdal-3.2.0/bin/gdal-config --with-geos-config=/usr/local/bin/geos-config")
without any reference toproj
.No needs to change OS or downgrade libraries.
I was experiencing the same problem today, but I could not use the other solution because I do not have root access. The problem was because the configure file used
pkgconfig
to check if proj exists, and I needed to add the path toproj.pc
to wherepkgconfig
checks.After
export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:/home/directory/local/proj_install/lib/pkgconfig
install.packages("sf", configure.args="--with-proj-include=/home/directory/local/proj_install/include --with-proj-lib=/home/directory/local/proj_install/lib --with-proj-data=/home/directory/local/proj_install/share/proj")
worked fine.