首页 > 解决方案 > 在 R 中安装最新版本的 xgboost 时出错

问题描述

嗨,尝试时遇到以下错误

    `install.packages("xgboost")`

错误信息:

`In file included from amalgamation/xgboost-all0.cc:68:0:
 amalgamation/../src/learner.cc: In member function ‘virtual void 
 xgboost::LearnerImpl::SaveModel(xgboost::Json*) const’:
 amalgamation/../src/learner.cc:378:24: error: invalid initialization of non-const reference of type 
 ‘xgboost::Json&’ from an rvalue of type ‘<brace-enclosed initializer list>’
 Json& out { *p_out };
                    ^
 amalgamation/../src/learner.cc: In member function ‘virtual void 
 xgboost::LearnerImpl::SaveConfig(xgboost::Json*) const’:
 amalgamation/../src/learner.cc:441:24: error: invalid initialization of non-const reference of type 
 ‘xgboost::Json&’ from an rvalue of type ‘<brace-enclosed initializer list>’
 Json& out { *p_out };
                    ^
 make: *** [amalgamation/xgboost-all0.o] Error 1
 ERROR: compilation failed for package ‘xgboost’`

─ 会话信息──────────────────────────────────────────────── ────────────────────────────────

setting  value                       
version  R version 3.6.0 (2019-04-26)
os       Red Hat Enterprise Linux    
system   x86_64, linux-gnu           
ui       RStudio                     
language (EN)                        
collate  en_AU.UTF-8                 
ctype    en_AU.UTF-8                 
tz       Australia/Brisbane          
date     2020-06-08  

但是,可以安装较旧的存档版本

packageurl <- "http://cran.r- 
project.org/src/contrib/Archive/xgboost/xgboost_0.90.0.2.tar.gz"
install.packages(packageurl, repos=NULL, type="source")

标签: rcompiler-errorsxgboost

解决方案


如果您是从源代码构建的,也许值得通过命令行(https://xgboost.readthedocs.io/en/latest/build.html#installing-the-development-version)从 github 尝试开发包:

git clone --recursive https://github.com/dmlc/xgboost
cd xgboost
git submodule init
git submodule update
mkdir build
cd build
cmake .. -DR_LIB=ON
make -j$(nproc)
make install

推荐阅读