I have recently upgraded my Ubuntu version from 20.04 to 22.04 LTS and Rstudio-server to 2023.06.02. The R version is 4.3.1. After that the shiny App I am developing, which ran OK on the previous version, was giving an error of the type ‘libproj.so.15 – cannot open shared file’. After reading various possible solutions, I reinstalled the "sf" package, which appeared to work OK. The error message then changed to the same, but referencing ‘libproj.so.26’, so I tried re-install ‘rgdal’. This gave the following error message:
> remove.packages("rgdal")
Removing package from ‘/home/denis/R/x86_64-pc-linux-gnu-library/4.3’
(as ‘lib’ is unspecified)
Error in remove.packages : there is no package called ‘rgdal’
> install.packages("rgdal")
Installing package into ‘/home/denis/R/x86_64-pc-linux-gnu-library/4.3’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/rgdal_1.6-7.tar.gz'
Content type 'application/x-gzip' length 4351163 bytes (4.1 MB)
==================================================
downloaded 4.1 MB
* installing *source* package ‘rgdal’ ...
** package ‘rgdal’ successfully unpacked and MD5 sums checked
** using staged installation
configure: R_HOME: /usr/lib/R
configure: CC: gcc
configure: CXX: g++ -std=gnu++17
configure: CFLAGS: -g -O2 -fdebug-prefix-map=/build/r-base-aeZVAy/r-base-4.3.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2
configure: CPPFLAGS:
configure: CXXFLAGS: -g -O2 -fdebug-prefix-map=/build/r-base-aeZVAy/r-base-4.3.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2
configure: LDFLAGS: -Wl,-Bsymbolic-functions -Wl,-z,relro
configure: LDFLAGS: -Wl,-Bsymbolic-functions -Wl,-z,relro
configure: CXX17 is: g++, CXX17STD is: -std=gnu++17
configure: CXX is: g++ -std=gnu++17
configure: C++17 support available
configure: rgdal: 1.6-7
checking for /usr/bin/svnversion... no
configure: svn revision: 1203
checking for gdal-config... /usr/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 3.4.1
checking GDAL version != 3.6.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/share/gdal/stateplane.csv readable... yes
configure: pkg-config proj exists, will use it
configure: PROJ version: 8.2.1
configure: PROJ CPP flags: -DPROJ_H_API
configure: PROJ LIBS: -lproj
checking PROJ header API:... yes
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 the compiler supports GNU C++... yes
checking whether g++ -std=gnu++17 accepts -g... yes
checking for g++ -std=gnu++17 option to enable C++11 features... none needed
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... 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/include/gdal -DPROJ_H_API
configure: Package LIBS: -L/usr/lib -lgdal -lproj
configure: creating ./config.status
config.status: creating src/Makevars
** libs
using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
using C++ compiler: ‘g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
using C++17
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I/usr/include/gdal -DPROJ_H_API -I'/usr/local/lib/R/site-library/sp/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-aeZVAy/r-base-4.3.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c OGR_write.cpp -o OGR_write.o
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I/usr/include/gdal -DPROJ_H_API -I'/usr/local/lib/R/site-library/sp/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-aeZVAy/r-base-4.3.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c gdal-bindings.cpp -o gdal-bindings.o
gcc -I"/usr/share/R/include" -DNDEBUG -I/usr/include/gdal -DPROJ_H_API -I'/usr/local/lib/R/site-library/sp/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-aeZVAy/r-base-4.3.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c init.c -o init.o
gcc -I"/usr/share/R/include" -DNDEBUG -I/usr/include/gdal -DPROJ_H_API -I'/usr/local/lib/R/site-library/sp/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-aeZVAy/r-base-4.3.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c inverser.c -o inverser.o
gcc -I"/usr/share/R/include" -DNDEBUG -I/usr/include/gdal -DPROJ_H_API -I'/usr/local/lib/R/site-library/sp/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-aeZVAy/r-base-4.3.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c local_stubs.c -o local_stubs.o
In file included from local_stubs.c:3:
/usr/local/lib/R/site-library/sp/include/sp_xports.c: In function ‘RGDAL_Polygon_c’:
/usr/local/lib/R/site-library/sp/include/sp_xports.c:60:22: error: ‘DOUBLE_EPS’ undeclared (first use in this function)
60 | if (fabs(area) < DOUBLE_EPS) {
| ^~~~~~~~~~
/usr/local/lib/R/site-library/sp/include/sp_xports.c:60:22: note: each undeclared identifier is reported only once for each function it appears in
/usr/local/lib/R/site-library/sp/include/sp_xports.c: In function ‘RGDAL_Polygons_c’:
/usr/local/lib/R/site-library/sp/include/sp_xports.c:203:18: error: ‘DOUBLE_EPS’ undeclared (first use in this function)
203 | fuzz = R_pow(DOUBLE_EPS, (2.0/3.0));
| ^~~~~~~~~~
make: *** [/usr/lib/R/etc/Makeconf:191: local_stubs.o] Error 1
ERROR: compilation failed for package ‘rgdal’
* removing ‘/home/denis/R/x86_64-pc-linux-gnu-library/4.3/rgdal’
Warning in install.packages :
installation of package ‘rgdal’ had non-zero exit status
Although the problem is obviously with the installation, a short test script, below, gives the essential code that causes the problems.
library(sf) # various GIS objects and functions
library(rgdal) # for readOGR function (deprecated!)
library(raster) # raster processing, uses GDAL objects
fnms <- c('at', 'ct', 'dams', 'md2', 'smr250', 'snr250')
files <- paste0(fnms, '.tif')
# creates a raster stack with the 6 factors as layers
fL <- raster::stack(files)
The data files if needed are available from https://bio-met.co.uk/file_transfer/EF_maps.zip.
This gives the error:
> source("~/.active-rstudio-document")
Error: package or namespace load failed for ‘rgdal’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/usr/lib/R/library/rgdal/libs/rgdal.so':
libgdal.so.26: cannot open shared object file: No such file or directory
In relation to some similar problems, but with older versions, it is suggested to install gdal libraries at the Ubuntu command line. When I do this, it seems the requisite libraries are already installed, as shown below:
sudo apt-get install -y libudunits2-dev libgdal-dev libgeos-dev libproj-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
libgdal-dev is already the newest version (3.4.1+dfsg-1build4).
libgeos-dev is already the newest version (3.10.2-1).
libgeos-dev set to manually installed.
libproj-dev is already the newest version (8.2.1-1).
libproj-dev set to manually installed.
libudunits2-dev is already the newest version (2.2.28-3).
The following package was automatically installed and is no longer required:
libssl1.1
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
At the moment I have run out of ideas as to what to try, not knowing how gdal should properly be configured on Ubuntu 22.04 or why the rgdal installation should give a compiler error on this version when it has worked perfectly in the past. Any suggestions would be very gratefully received. Is there a switch to use when installing rgdal from source to get it to compile properly, for example?
2
Answers
Thank you for those suggestions. I managed to install binaries from r2u, which did indeed solve the problem. Afterwards, I also made a small amendment to the code, retiring a reference to readOGR(), which was the only function from rgdal that was being used, so there is no longer dependence on the deprecated package.
Have you tried running
sudo apt update
and thensudo apt install r-cran-rgdal
?You may need to download from source as rgdal will be retired in Ocotober 2023. See here for similar issue