R package installation on MacOS: Image not found error - r

I tried to install rgdal package in R on my Mac machine, but the error message came out as below:
Installing package into ‘/Users/isong/Library/R/4.0/library’
(as ‘lib’ is unspecified)
* installing *source* package ‘rgdal’ ...
** using staged installation
configure: R_HOME: /usr/local/lib/R
configure: CC: gcc
configure: CXX: g++ -std=gnu++11
configure: CFLAGS: -g -O2
configure: CPPFLAGS: -I/usr/local/include
configure: CXXFLAGS: -g -O2
configure: LDFLAGS: -L/usr/local/lib
configure: LDFLAGS: -L/usr/local/lib
configure: CXX11 is: g++, CXX11STD is: -std=gnu++11
configure: CXX is: g++ -std=gnu++11
configure: C++11 support available
configure: rgdal: 1.5-19
checking for /usr/bin/svnversion... no
cat: inst/SVN_VERSION: No such file or directory
configure: svn revision:
checking for gdal-config... /usr/local/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 3.0.2
checking GDAL version >= 1.11.4... yes
checking GDAL version <= 2.5 or >= 3.0... yes
checking GDAL: linking with --libs only... yes
checking GDAL: gdal-config data directory readable... yes
checking GDAL: /usr/local/share/gdal/stateplane.csv readable... yes
configure: pkg-config proj not available
set PKG_CONFIG_PATH to the directory containing proj.pc
configure: PROJ version not determined using pkg-config proj
configure: PROJ CPP flags: -I/usr/local/include
configure: PROJ LIBS: -lproj
checking PROJ header API:... yes
configure: API to be used as yet undetermined, searching ...
configure: Using API: proj.h
checking whether the C++ compiler works... yes
[truncated]
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 proj.h usability... yes
checking proj.h presence... yes
checking for proj.h... yes
checking for proj_context_create in -lproj... yes
checking Using GDAL < 3 with PROJ >= 6... no
checking PROJ version >= 4.8.0... yes
checking PROJ: proj.db found and readable... yes
configure: Package CPP flags: -I/usr/local/include -DPROJ_H_API
configure: Package LIBS: -L/usr/local/lib -lgdal -lproj
configure: creating ./config.status
config.status: creating src/Makevars
** libs
[truncated]
installing to /Users/isong/Library/R/4.0/library/00LOCK-rgdal/00new/rgdal/libs
** R
** data
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘rgdal’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Users/isong/Library/R/4.0/library/00LOCK-rgdal/00new/rgdal/libs/rgdal.so':
dlopen(/Users/isong/Library/R/4.0/library/00LOCK-rgdal/00new/rgdal/libs/rgdal.so, 6): Library not loaded: #rpath/libproj.19.dylib
Referenced from: /Users/isong/Library/R/4.0/library/00LOCK-rgdal/00new/rgdal/libs/rgdal.so
Reason: image not found
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Users/isong/Library/R/4.0/library/rgdal’
* restoring previous ‘/Users/isong/Library/R/4.0/library/rgdal’
For your reference, I already configured and installed libproj, gdal, and geos in my machine and all of the dynamic libraries are located in /usr/local/lib.
Thank you.

Related

install from source spatial R libraries on Mac M1 with geos/proj/gdal from homebrew

I'm trying to install sf package from source to run it with latest version of geos/gdal/proj which were installed by homebrew. I'm using an Apple Silicon M1 computer with MacOS BigSur 11.3. and it seems that my issues are linked to this new Apple silicon chip. If any of you already faced the issue and could share some tips that'd be great.
Here is my command in R :
install_github("r-spatial/sf", configure.args = c("--with-proj-lib=/opt/homebrew/bin/", "--with-gdal-config=/opt/homebrew/bin/gdal-config", "--with-geos-config=/opt/homebrew/bin/geos-config"))
and the response is
Downloading GitHub repo r-spatial/sf#HEAD
✓ checking for file ‘/private/var/folders/50/g22y7v993hq6m6r4m3mm05_r0000gn/T/Rtmp5KWH5H/remotesc7c51a94ebf/r-spatial-sf-c99226b/DESCRIPTION’ (418ms)
─ preparing ‘sf’:
✓ checking DESCRIPTION meta-information ...
─ cleaning src
─ running ‘cleanup’
─ checking for LF line-endings in source and make files and shell scripts (629ms)
─ checking for empty or unneeded directories
─ building ‘sf_0.9-9.tar.gz’
* installing *source* package ‘sf’ ...
** using staged installation
configure: CC: clang -mmacosx-version-min=10.13
configure: CXX: clang++ -mmacosx-version-min=10.13 -std=gnu++11
configure: gdal-config set to /opt/homebrew/bin/gdal-config
checking gdal-config exists... yes
checking gdal-config executable... yes
checking gdal-config usability... yes
configure: GDAL: 3.2.2
checking GDAL version >= 2.0.1... yes
checking for gcc... clang -mmacosx-version-min=10.13
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 clang -mmacosx-version-min=10.13 accepts -g... yes
checking for clang -mmacosx-version-min=10.13 option to accept ISO C89... none needed
checking how to run the C preprocessor... clang -mmacosx-version-min=10.13 -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... rm: conftest.dSYM: is a directory
rm: conftest.dSYM: is a directory
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... no
checking GDAL: linking with --libs and --dep-libs... no
ld: warning: ignoring file /opt/homebrew/Cellar/gdal/3.2.2_4/lib/libgdal.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
"_GDALAllRegister", referenced from:
_main in gdal_test-e29770.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: warning: directory not found for option '-L/opt/homebrew/Cellar/libdap/3.20.7/lib64'
ld: library not found for -lcrypto
clang: error: linker command failed with exit code 1 (use -v to see invocation)
configure: Install failure: compilation and/or linkage problems.
configure: error: GDALAllRegister not found in libgdal.
ERROR: configuration failed for package ‘sf’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/sf’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/sf’
Warning message:
In i.p(...) :
installation of package ‘/var/folders/50/g22y7v993hq6m6r4m3mm05_r0000gn/T//Rtmp5KWH5H/filec7c4271077b/sf_0.9-9.tar.gz’ had non-zero exit status
When I try to do the same for rgdal I get the same result. And if I do it with rgeos, I get the similar error:
...
checking geos: linking with libgeos_c... no
checking geos: linking with -L/opt/homebrew/Cellar/geos/3.9.1/lib -lgeos_c -lgeos -lm... no
ld: warning: ignoring file /opt/homebrew/Cellar/geos/3.9.1/lib/libgeos_c.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/geos/3.9.1/lib/libgeos.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
...
I'm a bit new at this so let me know if you need more info.
Thanks,

Upgrade GEOS version on shiny apps.io

It seems that the current version of GEOS available on shinyapps.io is not at the right level.
This is the error message I am getting when trying to deploy my app:
** package ‘lwgeom’ successfully unpacked and MD5 sums checked
** using staged installation configure: CC: gcc configure: CXX: g++ -std=gnu++11 configure: pkg-config proj exists, will use it configure: PROJ: 4.9.2 checking for pj_init_plus in -lproj... yes
checking PROJ:
epsg found and readable... yes configure: POSTGIS_PROJ_VERSION: 49
checking for geos-config... /usr/bin/geos-config checking geos-config
usability... yes configure: GEOS: 3.5.1 checking GEOS version >=
3.6.0... no
configure: error: upgrade GEOS to 3.6.0 or later
ERROR: configuration failed for package ‘lwgeom’
removing ‘/opt/R/4.0.0/lib/R/library/lwgeom’
Is there anything I could do to by-pass this problem waiting for an update on the shiny apps side?
Thank you in advance.

Error installing R package sf 0.9.0 after updating gdal on macOS

I've had sf and rproj working on mac forever, and still working since upgrading to Catalina / R 3.6.2.
I tried to install the latest version of sf (0.9.0), both from CRAN and the dev version, and get errors both ways, configure: error: libproj not found in standard or given locations.
I've gone through and removed every last trace of gdal and proj on my computer, uninstalled both, reinstalled, and still same issue. And now, trying to install older versions of sf (0.8.1) that I know worked on my computer also fails. Absolutely stumped here!
GDAL 2.4.4, released 2020/01/08
R v3.6.2
macOS 10.15.3
configure: CC: clang
configure: CXX: clang++ -std=gnu++11
checking for gdal-config... /usr/local/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 2.4.4
checking GDAL version >= 2.0.1... yes
checking for gcc... clang
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 clang accepts -g... yes
checking for clang option to accept ISO C89... none needed
checking how to run the C preprocessor... clang -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/Cellar/gdal/2.4.4_2/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.4.4
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:... no
configure: error: libproj not found in standard or given locations.
for rgdal...
* installing *source* package ‘rgdal’ ...
** package ‘rgdal’ successfully unpacked and MD5 sums checked
** using staged installation
configure: R_HOME: /Library/Frameworks/R.framework/Resources
configure: CC: clang
configure: CXX: clang++ -std=gnu++11
configure: C++11 support available
configure: rgdal: 1.4-7
checking for /usr/bin/svnversion... yes
configure: svn revision: 845
checking for gdal-config... /usr/local/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 2.4.4
checking C++11 support for GDAL >= 2.3.0... yes
checking GDAL version >= 1.11.4... yes
checking GDAL version <= 2.5 or >= 3.0... yes
checking gdal: linking with --libs only... yes
checking GDAL: gdal-config data directory readable... yes
checking GDAL: /usr/local/Cellar/gdal/2.4.4_2/share/gdal/pcs.csv readable... yes
configure: pkg-config proj not available
set PKG_CONFIG_PATH to the directory containing proj.pc
configure: PROJ version not determined using pkg-config proj
configure: proj CPP flags: -I/usr/local/Cellar/gdal/2.4.4_2/include
configure: PROJ LIBS: -lproj
checking PROJ header API:... proj_api.h
checking proj_api.h presence and usability... no
configure: error: proj_api.h not found in standard or given locations.
ERROR: configuration failed for package ‘rgdal’
* removing ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal
Finally found a solution after many hours of digging here if anyone else comes across this problem.
A solution that works for me. I have posted it in:
https://biostatsr.blogspot.com/2021/05/install-sf-from-github-source-in-macosx.html
In terminal. You must have MacBrew installed. If not, use:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then
brew install proj
brew install gdal
brew install geos
sudo R
Then in R:
library("devtools")
install_github("r-spatial/sf", configure.args = "--with-proj-include=/usr/local/include --with-proj-lib=/usr/local/lib")
And...
packageVersion("sf")
[1] ‘0.9.9’

R: cannot install 'rgdal' package on Ubuntu 14.04

I have R (ver. 3.1.2) installed and I tried to install rgdal package. First I downloaded the package source (tar.gz) from here. Finally I installed the sp package on which rgdal depends. Then I run R and typed install.packages("/home/umberto/Scaricati/rgdal_1.1-3.tar.gz").
It seems it cannot find lgdal, below is the error I received:
Installing package into ‘/home/umberto/R/x86_64-pc-linux-gnu-library/3.1’
(as ‘lib’ is unspecified)
inferring 'repos = NULL' from 'pkgs'
* installing *source* package ‘rgdal’ ...
** package ‘rgdal’ successfully unpacked and MD5 sums checked
configure: CC: gcc -std=gnu99
configure: CXX: g++
configure: rgdal: 1.1-3
checking for /usr/bin/svnversion... yes
configure: svn revision: 594
checking for gdal-config... /usr/local/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 1.11.0
checking GDAL version >= 1.6.3... yes
checking for gcc... gcc -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 -std=gnu99 accepts -g... yes
checking for gcc -std=gnu99 option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -std=gnu99 -E
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... no
checking gdal: linking with --libs and --dep-libs... no
/usr/bin/ld: cannot find -lgdal
collect2: error: ld returned 1 exit status
/usr/bin/ld: cannot find -lgdal
collect2: error: ld returned 1 exit status
configure: Install failure: compilation and/or linkage problems.
configure: error: GDALAllRegister not found in libgdal.
ERROR: configuration failed for package ‘rgdal’
* removing ‘/home/umberto/R/x86_64-pc-linux-gnu-library/3.1/rgdal’
Warning message:
In install.packages("/home/umberto/Scaricati/rgdal_1.1-3.tar.gz") :
installation of package ‘/home/umberto/Scaricati/rgdal_1.1-3.tar.gz’ had non-zero exit status

Error while installing RMySQL (MySQL 5.6.14 in Ubuntu 13.04)

I'm trying to install RMySQL in Ubuntu 13.04 when using MySQL v5.6.14. Ubuntu does not have apt-get support for MySQL 5.6.14, so I had to install it manually. Now when I try to install RMySQL I get the following:
(It looks like the package files are not created? But I'm not sure why or how to debug it.)
elad#elad-ThinkPad-T430s:~/tmp$ sudo R CMD INSTALL --configure-args='--with-mysql-inc=/opt/mysql/server-5.6/include --with-mysql-lib=/opt/mysql/server-5.6/lib' RMySQL_0.9-3.tar.gz
* installing to library ‘/usr/local/lib/R/site-library’
* installing *source* package ‘RMySQL’ ...
** package ‘RMySQL’ successfully unpacked and MD5 sums checked
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking how to run the C preprocessor... gcc -E
checking for compress in -lz... yes
checking for getopt_long in -lc... yes
checking for mysql_init in -lmysqlclient... no
checking for egrep... 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 mysql.h usability... no
checking mysql.h presence... no
checking for mysql.h... no
configure: creating ./config.status
config.status: creating src/Makevars
** libs
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I/opt/mysql/server-5.6/include -fpic -O2 -pipe -g -c RS-DBI.c -o RS-DBI.o
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I/opt/mysql/server-5.6/include -fpic -O2 -pipe -g -c RS-MySQL.c -o RS-MySQL.o
gcc -std=gnu99 -shared -o RMySQL.so RS-DBI.o RS-MySQL.o -L/opt/mysql/server-5.6/lib -lmysqlclient -lz -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/RMySQL/libs
** R
** inst
** preparing package for lazy loading
Creating a generic function for ‘format’ from package ‘base’ in package ‘RMySQL’
Creating a generic function for ‘print’ from package ‘base’ in package ‘RMySQL’
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error : .onLoad failed in loadNamespace() for 'RMySQL', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/usr/local/lib/R/site-library/RMySQL/libs/RMySQL.so':
libmysqlclient.so.18: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/usr/local/lib/R/site-library/RMySQL’
* restoring previous ‘/usr/local/lib/R/site-library/RMySQL’
Update:
This ended up being a LD_LIBRARY_PATH issue. Adding the following to /usr/bin/R solved it:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH/opt/mysql/server-5.6/lib
export LD_LIBRARY_PATH
Did you run ldconfig after installing the library locally?
Does ldconfig -p return something regarding mysql?
On my box, with default MySQL libraries from Ubuntu [lines wrapped by hand]
edd#max:~$ ldconfig -p | grep mysql
libmysqlclient.so.18 (libc6,x86-64) => \
/usr/lib/x86_64-linux-gnu/libmysqlclient.so.18
libmysqlclient.so (libc6,x86-64) => \
/usr/lib/x86_64-linux-gnu/libmysqlclient.so
edd#max:~$

Resources