Linux HPC Conda环境安装GitHub版terra/sf包遇GDAL错误求助
问题描述
在Linux HPC的Conda环境中,尝试从R内安装GitHub上的terra开发版或sf包时出现链接错误,具体错误信息如下:
/****/miniconda/envs/env1/bin/../lib/gcc/x86_64-conda-linux-gnu/13.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /****/miniconda/envs/env1/lib/libgdal.so: undefined reference to `posix_spawnp@GLIBC_2.15' /****/miniconda/envs/env1/bin/../lib/gcc/x86_64-conda-linux-gnu/13.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /****/miniconda/envs/env1/lib/libgdal.so: undefined reference to `memcpy@GLIBC_2.14' collect2: error: ld returned 1 exit status configure: error: GDALAllRegister not found in libgdal.
通过Conda配置文件添加r-sf、r-terra可正常安装正式版,但需安装GitHub开发版。当前Conda配置片段:
name: R_Conda channels: - conda-forge - anaconda dependencies: - r-base=4.3.2 - proj - geos - gdal - fontconfig-devel-cos7-aarch64
解决建议
错误根源是Conda环境中的GDAL库依赖的GLIBC版本与HPC系统提供的版本不兼容,或混合通道安装导致依赖冲突。以下是针对性解决方案:
1. 统一Conda通道优先级
混合conda-forge和anaconda通道易导致依赖版本不匹配,修改~/.condarc配置文件,强制使用conda-forge作为最高优先级通道:
channels: - conda-forge - defaults channel_priority: strict
之后删除原有环境,重新创建干净环境。
2. 创建专属开发环境
新建仅依赖conda-forge的环境,明确指定地理依赖版本,确保与R 4.3.2兼容:
conda create -n r_geo_dev r-base=4.3.2 gdal=3.6 proj=9.1 geos=3.11 r-devtools -c conda-forge --strict-channel-priority conda activate r_geo_dev
激活环境后再尝试安装开发版包。
3. 指定R编译依赖路径
在R中安装前,强制编译器使用Conda环境内的GDAL库,避免调用系统库:
# 设置环境变量指向Conda库目录 Sys.setenv(LD_LIBRARY_PATH = paste0(Sys.getenv("CONDA_PREFIX"), "/lib")) Sys.setenv(CPATH = paste0(Sys.getenv("CONDA_PREFIX"), "/include")) # 安装terra开发版,显式指定GDAL路径 remotes::install_github( "rspatial/terra", configure.args = c( "--with-gdal-lib=", Sys.getenv("CONDA_PREFIX"), "/lib", "--with-gdal-include=", Sys.getenv("CONDA_PREFIX"), "/include" ) )
4. 使用Conda编译工具链
安装Conda提供的GCC工具链,确保编译时使用与环境兼容的编译器,而非系统默认版本:
conda install -c conda-forge gcc_linux-64 gxx_linux-64
激活环境后再执行R内的安装命令。
内容的提问来源于stack exchange,提问作者Ahmed El-Gabbas
相关产品推荐
相关产品推荐

