r-rstan C++14在安装时出错(centos)



安装rstan时出现以下错误:

Error in .shlib_internal(args) :
C++14 standard requested but CXX14 is not defined

从研究中了解到C++14编译器应该是可用的。如何在配置R时安装相同的。使用以下命令配置R

./configure --with-readline=no --with-x=no

和安装

yum install -y devtoolset-6

但仍然无法更新C++14,并且rstan给出错误

Default C++ compiler:      g++   -g -O2
C++98 compiler:            g++  -g -O2
C++11 compiler:            g++ -std=gnu++11 -g -O2
C++14 compiler:            g++   -g -O2  
C++17 compiler:              
Fortran 90/95 compiler:    gfortran -g -O2
Obj-C compiler: 

setup.sh

yum -y update
yum install -y centos-release-scl
yum install -y devtoolset-6
yum install -y devtoolset-6-gcc-gfortran
scl enable devtoolset-6 bash
scl enable devtoolset-6-gcc-gfortran bash
mkdir packages
cd packages
wget -qO- 
https://downloads.sourceforge.net/project/libpng/zlib/1.2.8/zlib- 
1.2.8.tar.gz | tar zvx
cd zlib-1.2.8
./configure
make
make install
cd ..
wget -qO- http://downloads.sourceforge.net/pcre/pcre-8.35.tar.gz | 
tar xzv
cd pcre-8.35
./configure
make
make install
cd ..
wget -qO- http://tukaani.org/xz/xz-5.2.2.tar.gz | tar xzv
cd xz-5.2.2
./configure
make
make install
cd ..
wget -qO- https://curl.haxx.se/download/curl-7.47.1.tar.gz | tar xzv
cd curl-7.47.1
./configure
make
make install
cd ..

wget -qO- https://cran.r-project.org/src/base/R-3/R-3.4.4.tar.gz | 
tar xzv
cd R-3.4.4
./configure --with-readline=no --with-x=no --prefix=/packages/R-3.4.4 
F77=gfortran
make
make install

我也遇到了这个问题,在这里我记录了如何解决它。

关键点是安装正确的g++并配置它。

首先,安装g++版本>=5作为https://github.com/stan-dev/rstan/wiki/Installing-RStan-on-Linux说:

使用RStan需要g++版本4.9和更高版本

这里我正在安装g++8(您可以根据自己的意愿更改版本(:

运行

$ sudo yum install centos-release-scl
$ sudo yum install devtoolset-8-gcc*

现在您在操作系统中有了一个替代g++和默认g++。

您可以启用此功能并检查版本:

$ scl enable devtoolset-8 bash
$ gcc --version
$ g++ --version

查找其位置:

$ which g++
/opt/rh/devtoolset-8/root/usr/bin/g++

接下来,您需要配置~/.R/Makevars,使用vim(或其他编辑器(将以下内容放入其中:

CXX14FLAGS=-O3 -march=native -mtune=native -fPIC
CXX14=/opt/rh/devtoolset-8/root/usr/bin/g++

或者使用R命令:

dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, "Makevars")
if (!file.exists(M)) file.create(M)
cat("nCXX14FLAGS=-O3 -march=native -mtune=native -fPIC",
"CXX14=/opt/rh/devtoolset-8/root/usr/bin/g++", # or clang++ but you may need a version postfix
file = M, sep = "n", append = TRUE)

注意:这些R命令是从https://github.com/stan-dev/rstan/wiki/Configuring-C-Toolchain-for-Linux但是CXX14标志是根据上面的位置修改的。

现在,您可以立即安装rstan包:

install.packages("rstan")

希望这能有所帮助。


PS:R用户可以使用这种方法以类似的方式修改编译器标志。

这就是我的工作原理:

CXX_STD=CXX14

CXX14=g++-标准=c++11

CXX14FLAGS=-O3-fPIC-Wno未使用的变量-Wno已使用的函数-DBOOST_PHOENIX_NO_ARIADIC_EXPRESS

您不需要重新编译R,但至少需要g++-4.9(或clang++-3.4(,并在~/中定义CXX14 = g++。R/Makevars配置文件。此外,您通常需要CXX14FLAGS = -fPIC,最好使用CXX14FLAGS = -O3 -mtune = native -march = native -fPIC。所有这些都有一个wiki页面。

做了以下更改,现在工作正常。需要定义gcc PATH,并使用yum-install-y-devtoolset-6 for R-3.4.4。感谢的帮助

yum install -y centos-release-scl
yum install -y devtoolset-6
yum install -y bzip2-devel
source scl_source enable devtoolset-6
also added the Path to gcc in build.sh 
export PATH=/opt/rh/devtoolset-6/root/bin:$PATH

我也遇到了同样的问题。这是我的解决方案,以防对他人有所帮助。

在CentOS 7上,I:

  1. 从这里安装了V8标头和共享库:https://pkgs.org/download/v8-devel41(EPEL_x86_64(

  2. 将gcc从版本4提升到9.3.1

在R,I中:

  1. 删除rstan和StanHeaders

  2. 在新的R会话中安装了rstan和StanHeader

在斯坦论坛上发表的讨论如下:https://discourse.mc-stan.org/t/problem-installing-rstan-2-21-using-r-4-0-1-on-centos-7/17784/9

最新更新