ArchLinux服务器RStudio Server安装sf包时GDAL触发非法操作求助
问题:ArchLinux上安装R的sf/rgdal包时触发非法操作错误
环境信息
- 服务器配置:双Xeon E5-2470处理器、48GB内存
- 系统:ArchLinux
- R环境:RStudio Server(2022.07.999 build 999)
错误详情
执行install.packages("sf")时出现非法操作错误,R直接终止,错误日志如下:
** testing if installed package can be loaded from temporary location *** caught illegal operation *** address 0x55b94289a1e0, cause 'unknown' Traceback: 1: CPL_gdal_init() 2: load_gdal() 3: fun(libname, pkgname) 4: doTryCatch(return(expr), name, parentenv, handler) 5: tryCatchOne(expr, names, parentenv, handlers[[1L]]) 6: tryCatchList(expr, classes, parentenv, handlers) 7: tryCatch(fun(libname, pkgname), error = identity) 8: runHook(".onLoad", env, package.lib, package) 9: loadNamespace(package, lib.loc) 10: doTryCatch(return(expr), name, parentenv, handler) 11: tryCatchOne(expr, names, parentenv, handlers[[1L]]) 12: tryCatchList(expr, classes, parentenv, handlers) 13: tryCatch({ attr(package, "LibPath") <- which.lib.loc ns <- loadNamespace(package, lib.loc) env <- attachNamespace(ns, pos = pos, deps, exclude, include.only)}, error = function(e) { P <- if (!is.null(cc <- conditionCall(e))) paste(" in", deparse(cc)[1L]) else "" msg <- gettextf("package or namespace load failed for %s%s:\n %s", sQuote(package), P, conditionMessage(e)) if (logical.return && !quietly) message(paste("Error:", msg), domain = NA) else stop(msg, call. = FALSE, domain = NA)}) 14: library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE) 15: withCallingHandlers(expr, packageStartupMessage = function(c) tryInvokeRestart("muffleMessage")) 16: suppressPackageStartupMessages(library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE)) 17: doTryCatch(return(expr), name, parentenv, handler) 18: tryCatchOne(expr, names, parentenv, handlers[[1L]]) 19: tryCatchList(expr, classes, parentenv, handlers) 20: tryCatch(expr, error = function(e) { call <- conditionCall(e) if (!is.null(call)) { if (identical(call[[1L]], quote(doTryCatch))) call <- sys.call(-4L) dcall <- deparse(call, nlines = 1L) prefix <- paste("Error in", dcall, ": ") LONG <- 75L sm <- strsplit(conditionMessage(e), "\n")[[1L]] w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w") if (is.na(w)) w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], type = "b") if (w > LONG) prefix <- paste0(prefix, "\n ") } else prefix <- "Error : " msg <- paste0(prefix, conditionMessage(e), "\n") .Internal(seterrmessage(msg[1L])) if (!silent && isTRUE(getOption("show.error.messages"))) { cat(msg, file = outFile) .Internal(printDeferredWarnings()) } invisible(structure(msg, class = "try-error", condition = e))}) 21: try(suppressPackageStartupMessages(library(pkg_name, lib.loc = lib, character.only = TRUE, logical.return = TRUE))) 22: tools:::.test_load_package("sf", "/home/trevor/R/x86_64-pc-linux-gnu-library/4.2/00LOCK-sf/00new") An irrecoverable exception occurred. R is aborting now ... ERROR: loading failed * removing ‘/home/trevor/R/x86_64-pc-linux-gnu-library/4.2/sf’ Warning in install.packages : installation of package ‘sf’ had non-zero exit status
执行install.packages("rgdal")时出现类似错误。
当前GDAL配置
已通过pacman安装GDAL 3.5.0-4,且所有可选依赖均已安装,包信息如下:
pacman -Qi gdal Name : gdal Version : 3.5.0-4 Description : A translator library for raster and vector geospatial data formats Architecture : x86_64 URL : https://gdal.org/ Licenses : custom Groups : None Provides : None Depends On : proj blosc crypto++ curl libdeflate expat libfreexl geos libgeotiff giflib libjpeg-turbo json-c xz libxml2 lz4 unixodbc ocl-icd openssl pcre2 libpng qhull libspatialite sqlite libtiff xerces-c zlib zstd Optional Deps : arrow: Arrow/Parquet support [installed] cfitsio: FITS support [installed] hdf5: HDF5 support [installed] libheif: HEIF support [installed] mariadb-libs: MySQL support [installed] netcdf: netCDF support [installed] openexr: EXR support [installed] openjpeg2: JP2 support [installed] podofo: PDF support [installed] poppler: PDF support [installed] postgresql-libs: PostgreSQL support [installed] libwebp: WebP support [installed] Required By : python-gdal Optional For : None Conflicts With : None Replaces : None Installed Size : 27.98 MiB Packager : Bruno Pagani <archange@archlinux.org> Build Date : Fri Jul 1 21:44:46 2022 Install Date : Sun Jul 24 16:22:48 2022 Install Reason : Explicitly installed Install Script : No Validated By : Signature
解决方法
1. 降级GDAL版本
ArchLinux的GDAL包更新较快,3.5.0-4可能和当前R的sf/rgdal版本存在兼容性问题。可以尝试降级到更稳定的版本:
- 从Arch Linux Archive中下载旧版本的GDAL包(比如3.4.x系列)
- 执行
pacman -U /path/to/gdal-old-version.pkg.tar.zst进行降级 - 降级后重新运行
install.packages("sf")
2. 从源码编译安装时指定GDAL路径
如果降级GDAL不可行,可手动编译安装R包,强制指定系统GDAL的路径:
install.packages("sf", configure.args = c("--with-gdal-config=/usr/bin/gdal-config", "--with-proj-include=/usr/include/proj", "--with-proj-lib=/usr/lib"))
或者先安装rgdal:
install.packages("rgdal", configure.args = "--with-gdal-config=/usr/bin/gdal-config")
3. 检查CPU指令集兼容性
Xeon E5-2470是Sandy Bridge架构,部分新编译的GDAL包可能使用了该CPU不支持的指令集(比如AVX2)。可通过以下命令检查:
objdump -d /usr/bin/gdalinfo | grep -i avx
如果发现AVX2等指令,说明包编译时启用了不兼容的优化,需要重新编译GDAL并禁用这些指令,或使用兼容旧CPU的预编译包。
4. 更新系统和R环境
确保系统处于最新状态:
pacman -Syu
同时更新R到最新版本,再尝试安装sf包。
内容的提问来源于stack exchange,提问作者Trevor
相关产品推荐
相关产品推荐

