在 linux 中为 R 安装 xgboost 时出错

error in installing xgboost for R in linux

我正在尝试在我的 linux 服务器上安装 xgboost R 包,使用:

install.packages("xgboost", lib = "/usr/lib64/R/library")

它给我一个错误:

trying URL 'https://cran.rstudio.com/src/contrib/xgboost_0.6.4.1.tar.gz'
Content type 'application/x-gzip' length 596978 bytes (582 KB)
==================================================
downloaded 582 KB

* installing *source* package ‘xgboost’ ...
** package ‘xgboost’ successfully unpacked and MD5 sums checked
configure: creating ./config.status
config.status: creating src/Makevars
** libs
g++ -m64 -std=gnu++0x -I/usr/include/R -DNDEBUG -I./include -I./dmlc-core/include -I./rabit/include -I. -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0 -DDMLC_ENABLE_STD_THREAD=0 -DDMLC_DISABLE_STDIN=1 -DDMLC_LOG_CUSTOMIZE=1 -DXGBOOST_CUSTOMIZE_LOGGER=1 -DRABIT_CUSTOMIZE_MSG_ -DRABIT_STRICT_CXX98_  -I/usr/local/include  -fopenmp  -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -c xgboost_R.cc -o xgboost_R.o
In file included from ./dmlc-core/include/dmlc/logging.h:15,
                 from xgboost_R.cc:2:
./dmlc-core/include/dmlc/./base.h:71: note: #pragma message: Will need g++-4.6 or higher to compile allthe features in dmlc-core, compile without c++0x, some features may be disabled
xgboost_R.cc: In function ‘SEXPREC* XGBoosterSetAttr_R(SEXPREC*, SEXPREC*, SEXPREC*)’:
xgboost_R.cc:412: error: ‘nullptr’ was not declared in this scope
make: *** [xgboost_R.o] Error 1
ERROR: compilation failed for package ‘xgboost’
* removing ‘/usr/lib64/R/library/xgboost’
Warning in install.packages :
  installation of package ‘xgboost’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/RtmpFDEVT8/downloaded_packages’
Updating HTML index of packages in '.Library'
Warning in install.packages :
  cannot create file '/usr/share/doc/R-3.4.2/html/packages.html', reason 'Permission denied'
Warning in install.packages :
  cannot update HTML package index

它说需要 g++-4.6 或更高版本。

我将服务器上的 gcc 从 4.4.7 更新到 4.9.2。但是,它仍然给我同样的错误。

有没有人知道这个问题。如何解决?

使 gccg++ 的较新版本为 R 做好准备的一种方法是强制它在系统 $PATH 的早期出现。除了改变 $PATH 之外,还可以利用 /usr/local/bin/ 通常在 /usr/bin 之前的事实,以便首选添加较新的版本。

所以假设我们在 /opt/gcc/gcc-4.9.2/ 中安装了一个新的 gcc 我们可以做

cd /usr/local/bin
sudo ln -s /opt/gcc/gcc-4.9.3/bin/gcc .
sudo ln -s /opt/gcc/gcc-4.9.3/bin/g++ .

这可能就足够了。 ldasar、...可以添加,但并不总是需要。根据需要调整路径,并确保 link 实际可执行文件(即 gcc)进入 /usr/local/bin.

检查gcc --version

我遇到了 xgboost 安装问题。但是,可以安装较旧的存档版本(“0.90.0.2”),并且可以正常工作!

packageurl <- "http://cran.r- 
project.org/src/contrib/Archive/xgboost/xgboost_0.90.0.2.tar.gz"

install.packages(packageurl, repos=NULL, type="source")