错误时安装rgdal软件包在ubuntu 22.04,rstudio-server 2023.06.02

mfuanj7w  于 2023-10-13  发布在  其他
关注(0)|答案(2)|浏览(164)

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

  1. > remove.packages("rgdal")
  2. Removing package from ‘/home/denis/R/x86_64-pc-linux-gnu-library/4.3
  3. (as lib is unspecified)
  4. Error in remove.packages : there is no package called rgdal
  5. > install.packages("rgdal")
  6. Installing package into ‘/home/denis/R/x86_64-pc-linux-gnu-library/4.3
  7. (as lib is unspecified)
  8. trying URL 'https://cloud.r-project.org/src/contrib/rgdal_1.6-7.tar.gz'
  9. Content type 'application/x-gzip' length 4351163 bytes (4.1 MB)
  10. ==================================================
  11. downloaded 4.1 MB
  12. * installing *source* package rgdal ...
  13. ** package rgdal successfully unpacked and MD5 sums checked
  14. ** using staged installation
  15. configure: R_HOME: /usr/lib/R
  16. configure: CC: gcc
  17. configure: CXX: g++ -std=gnu++17
  18. 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
  19. configure: CPPFLAGS:
  20. 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
  21. configure: LDFLAGS: -Wl,-Bsymbolic-functions -Wl,-z,relro
  22. configure: LDFLAGS: -Wl,-Bsymbolic-functions -Wl,-z,relro
  23. configure: CXX17 is: g++, CXX17STD is: -std=gnu++17
  24. configure: CXX is: g++ -std=gnu++17
  25. configure: C++17 support available
  26. configure: rgdal: 1.6-7
  27. checking for /usr/bin/svnversion... no
  28. configure: svn revision: 1203
  29. checking for gdal-config... /usr/bin/gdal-config
  30. checking gdal-config usability... yes
  31. configure: GDAL: 3.4.1
  32. checking GDAL version != 3.6.0... yes
  33. checking GDAL version >= 1.11.4... yes
  34. checking GDAL version <= 2.5 or >= 3.0... yes
  35. checking GDAL: linking with --libs only... yes
  36. checking GDAL: gdal-config data directory readable... yes
  37. checking GDAL: /usr/share/gdal/stateplane.csv readable... yes
  38. configure: pkg-config proj exists, will use it
  39. configure: PROJ version: 8.2.1
  40. configure: PROJ CPP flags: -DPROJ_H_API
  41. configure: PROJ LIBS: -lproj
  42. checking PROJ header API:... yes
  43. checking whether the C++ compiler works... yes
  44. checking for C++ compiler default output file name... a.out
  45. checking for suffix of executables...
  46. checking whether we are cross compiling... no
  47. checking for suffix of object files... o
  48. checking whether the compiler supports GNU C++... yes
  49. checking whether g++ -std=gnu++17 accepts -g... yes
  50. checking for g++ -std=gnu++17 option to enable C++11 features... none needed
  51. checking for stdio.h... yes
  52. checking for stdlib.h... yes
  53. checking for string.h... yes
  54. checking for inttypes.h... yes
  55. checking for stdint.h... yes
  56. checking for strings.h... yes
  57. checking for sys/stat.h... yes
  58. checking for sys/types.h... yes
  59. checking for unistd.h... yes
  60. checking for proj.h... yes
  61. checking for proj_context_create in -lproj... yes
  62. checking Using GDAL < 3 with PROJ >= 6... no
  63. checking PROJ version >= 4.8.0... yes
  64. checking PROJ: proj.db found and readable... yes
  65. configure: Package CPP flags: -I/usr/include/gdal -DPROJ_H_API
  66. configure: Package LIBS: -L/usr/lib -lgdal -lproj
  67. configure: creating ./config.status
  68. config.status: creating src/Makevars
  69. ** libs
  70. using C compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
  71. using C++ compiler: g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
  72. using C++17
  73. 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
  74. 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
  75. 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
  76. 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
  77. 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
  78. In file included from local_stubs.c:3:
  79. /usr/local/lib/R/site-library/sp/include/sp_xports.c: In function RGDAL_Polygon_c’:
  80. /usr/local/lib/R/site-library/sp/include/sp_xports.c:60:22: error: DOUBLE_EPS undeclared (first use in this function)
  81. 60 | if (fabs(area) < DOUBLE_EPS) {
  82. | ^~~~~~~~~~
  83. /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
  84. /usr/local/lib/R/site-library/sp/include/sp_xports.c: In function RGDAL_Polygons_c’:
  85. /usr/local/lib/R/site-library/sp/include/sp_xports.c:203:18: error: DOUBLE_EPS undeclared (first use in this function)
  86. 203 | fuzz = R_pow(DOUBLE_EPS, (2.0/3.0));
  87. | ^~~~~~~~~~
  88. make: *** [/usr/lib/R/etc/Makeconf:191: local_stubs.o] Error 1
  89. ERROR: compilation failed for package rgdal
  90. * removing ‘/home/denis/R/x86_64-pc-linux-gnu-library/4.3/rgdal
  91. Warning in install.packages :
  92. installation of package rgdal had non-zero exit status

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

  1. library(sf) # various GIS objects and functions
  2. library(rgdal) # for readOGR function (deprecated!)
  3. library(raster) # raster processing, uses GDAL objects
  4. fnms <- c('at', 'ct', 'dams', 'md2', 'smr250', 'snr250')
  5. files <- paste0(fnms, '.tif')
  6. # creates a raster stack with the 6 factors as layers
  7. fL <- raster::stack(files)

如果需要,可从https://bio-met.co.uk/file_transfer/EF_maps.zip获取数据文件。
这给出了错误:

  1. > source("~/.active-rstudio-document")
  2. Error: package or namespace load failed for rgdal in dyn.load(file, DLLpath = DLLpath, ...):
  3. unable to load shared object '/usr/lib/R/library/rgdal/libs/rgdal.so':
  4. libgdal.so.26: cannot open shared object file: No such file or directory

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

  1. sudo apt-get install -y libudunits2-dev libgdal-dev libgeos-dev libproj-dev
  2. Reading package lists... Done
  3. Building dependency tree... Done
  4. Reading state information... Done
  5. libgdal-dev is already the newest version (3.4.1+dfsg-1build4).
  6. libgeos-dev is already the newest version (3.10.2-1).
  7. libgeos-dev set to manually installed.
  8. libproj-dev is already the newest version (8.2.1-1).
  9. libproj-dev set to manually installed.
  10. libudunits2-dev is already the newest version (2.2.28-3).
  11. The following package was automatically installed and is no longer required:
  12. libssl1.1
  13. Use 'sudo apt autoremove' to remove it.
  14. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

目前,我已经用完了想法,以尝试什么,不知道如何gdal应该正确配置在Ubuntu 22. 04或为什么rgdal安装应该给给予一个编译器错误,在这个版本时,它已经完美地工作在过去。如有任何建议,将不胜感激。例如,当从源代码安装rgdal时,是否有一个开关可以使用,以使其正确编译?

roqulrg3

roqulrg31#

你有没有试过先运行sudo apt update,然后再运行sudo apt install r-cran-rgdal
您可能需要从源代码下载,因为rgdal将于2023年10月退役。类似问题见此

ehxuflar

ehxuflar2#

谢谢你的建议。我设法从r2u安装了二进制文件,这确实解决了问题。之后,我还对代码做了一个小小的修改,取消了对readOGR()的引用,这是rgdal中唯一使用的函数,因此不再依赖于弃用的包。

相关问题