在 ubuntu 22.04、rstudio-sever 2023.06.02 上安装 rgdal 包时出错

问题描述 投票:0回答:1

我最近将 Ubuntu 版本从 20.04 升级到 22.04 LTS,并将 Rstudio-server 升级到 2023.06.02。 R版本是4.3.1。之后,我正在开发的闪亮应用程序在以前的版本上运行正常,但给出了“libproj.so.15 - 无法打开共享文件”类型的错误。在阅读了各种可能的解决方案后,我重新安装了“sf”包,它似乎工作正常。然后错误消息更改为相同,但引用“libproj.so.26”,所以我尝试重新安装“rgdal”。这给出了以下错误消息:

> 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

虽然问题显然与安装有关,但下面的简短测试脚本给出了导致问题的基本代码。

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)

如果需要,数据文件可从 https://bio-met.co.uk/file_transfer/EF_maps.zip获得。

这给出了错误:

> 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

对于一些类似的问题,但对于旧版本,建议在Ubuntu命令行安装gdal库。当我这样做时,似乎已经安装了必需的库,如下所示:

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.

目前我已经不知道该尝试什么了,不知道如何在 Ubuntu 22.04 上正确配置 gdal,也不知道为什么 rgdal 安装在这个版本上会出现编译器错误,而在过去它工作得很好。如有任何建议,我们将非常感激。例如,从源代码安装 rgdal 时是否可以使用开关以使其正确编译?

r ubuntu-22.04 rstudio-server rgdal
1个回答
0
投票

您是否尝试过先跑步

sudo apt update
,然后
sudo apt install r-cran-rgdal

© www.soinside.com 2019 - 2024. All rights reserved.