You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Ubuntu22.04编译R 4.3.1遇libR.so未定义引用错误求助

问题

在Ubuntu 22.04上从源码编译R 4.3.1并安装到指定目录,执行了以下命令:

sudo sed -i.bak "/^#.*deb-src.*universe$/s/^# //g" /etc/apt/sources.list
sudo apt update
sudo apt build-dep r-base

./configure     --prefix=/data/shared/photon/opt/R/ubuntu22/${R_VERSION}     --enable-R-shlib     --enable-memory-profiling     --with-blas     --with-lapack
make -j 4

编译时出现链接错误:

make[3]: Entering directory '/root/R-4.3.1/src/main'
gcc -Wl,--export-dynamic -fopenmp  -L"../../lib" -L/usr/local/lib -o R.bin Rmain.o  -lR 
/usr/bin/ld: ../../lib/libR.so: undefined reference to `u_versionToString_58'
/usr/bin/ld: ../../lib/libR.so: undefined reference to `u_getVersion_58'
/usr/bin/ld: ../../lib/libR.so: undefined reference to `uloc_setDefault_58'
/usr/bin/ld: ../../lib/libR.so: undefined reference to `ucol_setStrength_58'
/usr/bin/ld: ../../lib/libR.so: undefined reference to `ucol_open_58'
/usr/bin/ld: ../../lib/libR.so: undefined reference to `ucol_close_58'
/usr/bin/ld: ../../lib/libR.so: undefined reference to `ucol_strcollIter_58'
/usr/bin/ld: ../../lib/libR.so: undefined reference to `ucol_setAttribute_58'
/usr/bin/ld: ../../lib/libR.so: undefined reference to `uiter_setUTF8_58'
/usr/bin/ld: ../../lib/libR.so: undefined reference to `ucol_getLocaleByType_58'

系统自带libicu70,libR由R源码提供,请问如何解决该问题?是否有无需apt即可安装到指定位置的Ubuntu22版R二进制包?

解决方案

一、解决编译链接错误

这些未定义引用属于ICU Unicode组件库,问题根源是R 4.3.1编译时未正确链接系统的libicu70,或者默认依赖的ICU版本(符号名里的_58对应ICU 58)与系统提供的libicu70不匹配。可按以下步骤修复:

  1. 指定ICU库路径重新配置
    在./configure命令中添加ICU相关参数,强制使用系统的libicu70:

    ./configure \
      --prefix=/data/shared/photon/opt/R/ubuntu22/${R_VERSION} \
      --enable-R-shlib \
      --enable-memory-profiling \
      --with-blas \
      --with-lapack \
      --with-icu=/usr
    

    Ubuntu 22.04的libicu头文件在/usr/include/x86_64-linux-gnu/unicode,库文件在/usr/lib/x86_64-linux-gnu,指定/usr作为根路径可让configure自动定位这些资源。

  2. 清理缓存后重新编译
    先清除之前的编译产物,再重新执行配置和编译:

    make clean
    ./configure [上述完整参数]
    make -j4
    
  3. 确保ICU开发包完整
    即便执行过apt build-dep r-base,仍可额外安装ICU开发包确认依赖:

    sudo apt install libicu-dev
    

二、无需apt安装的R二进制包

Ubuntu 22.04可用以下方式获取可直接部署到指定目录的R二进制包:

  • CRAN预编译tar包:CRAN为Ubuntu提供.tar.gz格式的预编译二进制包,下载后直接解压到目标目录即可使用。
  • conda离线部署:在有网络的机器上用conda-forge频道安装R到独立环境,将整个环境目录复制到目标机器,调整R_HOME环境变量和动态库路径(可使用patchelf工具修改二进制的rpath)。
  • 手动打包已安装的R:若其他机器已通过apt安装R 4.3.1,打包/usr/lib/R等核心目录,解压到目标路径后,配置环境变量即可使用。

内容的提问来源于stack exchange,提问作者doom4

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 02:55:21