无法从 CRAN 安装 xgboost

Can't install xgboost from CRAN

当我想在 cenos7(即 wsl2)中从 cran 安装 xgboost 时,我遇到了这个错误,而且我无法通过 google 消息找到任何线索:

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*) cons
’:
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’
* removing ‘/usr/lib64/R/library/xgboost’

环境是:

> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.6.0 tools_3.6.0

默认的 gcc 版本是 4.8.5,为了编译 'rstan' 我写

CXX14 = g++ -std=c++1y
CXX14FLAGS += -fPIC

进入文件 ~/.R/Makevars

如何才能成功安装xgboost?

尝试来自 github (https://xgboost.readthedocs.io/en/latest/build.html#installing-the-development-version) 的开发包:

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

使用默认目标时,会在构建区构建一个R包共享库。此外,安装目标在 build/R-package 下使用此共享库组装包文件并运行 R CMD INSTALL。