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

Linux集群无sudo权限下安装RcppArmadillo遇OpenMP编译错误求助

解决无sudo权限下Linux超算集群安装RcppArmadillo的编译错误

问题背景

在无sudo权限的Linux超算集群上,使用R 4.3.1、Rcpp 1.0.11安装RcppArmadillo时,执行install.packages('RcppArmadillo')或从GitHub安装均失败,报错核心为OpenMP相关函数omp_get_max_threads、omp_set_num_threads未定义,使用的编译器为GCC 4.8.5。

报错信息

using C++ compiler: ‘g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)’
g++ -std=gnu++11 -I"/home/yz909/R/lib64/R/include" -DNDEBUG -I../inst/include -I'/cache/home/yz909/R/lib64/R/library/Rcpp/include' -I/usr/local/include   -fopenmp -fpic  -g -O2  -c RcppArmadillo.cpp -o RcppArmadillo.o
RcppArmadillo.cpp: In function ‘int armadillo_get_number_of_omp_threads()’:
RcppArmadillo.cpp:103:32: error: ‘omp_get_max_threads’ was not declared in this scope
     return omp_get_max_threads();
                                ^
RcppArmadillo.cpp: In function ‘void armadillo_set_number_of_omp_threads(int)’:
RcppArmadillo.cpp:113:26: error: ‘omp_set_num_threads’ was not declared in this scope
     omp_set_num_threads(n);
                          ^
make: *** [RcppArmadillo.o] Error 1
ERROR: compilation failed for package ‘RcppArmadillo’
* removing ‘/cache/home/yz909/R/lib64/R/library/RcppArmadillo’

The downloaded source packages are in
        ‘/tmp/Rtmpk3pNYK/downloaded_packages’
Warning message:
In install.packages("RcppArmadillo") :
  installation of package ‘RcppArmadillo’ had non-zero exit status

解决方案

方案1:禁用OpenMP支持安装

如果不需要OpenMP并行功能,可直接在安装时禁用OpenMP:

install.packages("RcppArmadillo", configure.args = "--disable-openmp")

若从GitHub安装,使用:

devtools::install_github("RcppCore/RcppArmadillo", configure.args = "--disable-openmp")

方案2:手动配置OpenMP编译参数保留并行功能

若需要OpenMP,需确保编译时正确引入OpenMP头文件并链接库,在R中执行以下命令:

# 设置编译和链接参数
Sys.setenv(PKG_CXXFLAGS = "-fopenmp -I/usr/include", PKG_LIBS = "-fopenmp")
# 执行安装
install.packages("RcppArmadillo")

GCC 4.8.5的OpenMP头文件默认在/usr/include,添加-I/usr/include确保编译器能找到omp.h,-fopenmp同时用于编译和链接阶段。

方案3:切换至更高版本的GCC编译器

若集群提供了更高版本的GCC模块(如GCC 8及以上),先加载新版本编译器再安装:

# 在终端加载GCC模块(示例版本为8.3.0,需根据集群实际调整)
module load gcc/8.3.0

之后启动R,再执行install.packages('RcppArmadillo')即可。更高版本的GCC对C++11和OpenMP的支持更完善,能避免此类兼容性问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 23:50:22