简体   繁体   English

centos7上安装rlang时出现C99模式错误

[英]C99 mode error when installing rlang on centos7

I have created a docker image based on Centos7 and installed R with the Dockerfile below:我创建了一个基于 Centos7 的 docker 映像,并安装了 R 和下面的 Dockerfile:

FROM centos:7

ENV TZ=Etc/UTC

# OS Dependencies
RUN yum install -y \
    epel-release \
    centos-release-scl-rh \
    openblas-Rblas \
    devtoolset-8-toolchain \
    tre-devel \
    wget \
    libcurl-devel \
    && yum group install -y "Development Tools"

# Install R
RUN yum install -y \
    http://springdale.princeton.edu/data/springdale/7/x86_64/os/Computational/libRmath-devel-4.0.2-1.sdl7.x86_64.rpm \
    http://springdale.princeton.edu/data/springdale/7/x86_64/os/Computational/libRmath-4.0.2-1.sdl7.x86_64.rpm \
    http://springdale.princeton.edu/data/springdale/7/x86_64/os/Computational/R-java-devel-4.0.2-1.sdl7.x86_64.rpm \
    http://springdale.princeton.edu/data/springdale/7/x86_64/os/Computational/R-devel-4.0.2-1.sdl7.x86_64.rpm \
    http://springdale.princeton.edu/data/springdale/7/x86_64/os/Computational/R-core-devel-4.0.2-1.sdl7.x86_64.rpm \
    http://springdale.princeton.edu/data/springdale/7/x86_64/os/Computational/R-core-4.0.2-1.sdl7.x86_64.rpm

I am trying to install the R package rlang but am getting an error related to "C99" mode that I cannot resolve.我正在尝试安装 R package rlang ,但收到与“C99”模式相关的错误,我无法解决。

> install.packages("rlang", repos = "https://cran.rstudio.org")
Installing package into '/usr/lib64/R/library'
(as 'lib' is unspecified)
trying URL 'https://cran.rstudio.org/src/contrib/rlang_0.4.10.tar.gz'
Content type 'application/x-gzip' length 915685 bytes (894 KB)
==================================================
downloaded 894 KB

* installing *source* package 'rlang' ...
** package 'rlang' successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -m64 -I"/usr/include/R" -DNDEBUG -I./lib/  -I/usr/local/include  -fvisibility=hidden -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic  -c capture.c -o capture.o
gcc -m64 -I"/usr/include/R" -DNDEBUG -I./lib/  -I/usr/local/include  -fvisibility=hidden -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic  -c export.c -o export.o
In file included from export.c:1:0:
export/exported.c: In function 'rlang_env_bind_list':
export/exported.c:93:3: error: 'for' loop initial declarations are only allowed in C99 mode
   for (r_ssize i = 0; i < n; ++i) {
   ^
export/exported.c:93:3: note: use option -std=c99 or -std=gnu99 to compile your code
In file included from export.c:1:0:
export/exported.c: In function 'rlang_is_string':
export/exported.c:572:3: error: 'for' loop initial declarations are only allowed in C99 mode
   for (r_ssize i = 0; i < n; ++i) {
   ^
make: *** [export.o] Error 1
ERROR: compilation failed for package 'rlang'
* removing '/usr/lib64/R/library/rlang'

The downloaded source packages are in
        '/tmp/RtmpEmr8lk/downloaded_packages'
Updating HTML index of packages in '.Library'
Warning messages:
1: In install.packages("rlang", repos = "https://cran.rstudio.org") :
  installation of package 'rlang' had non-zero exit status
2: In file.create(f.tg) :
  cannot create file '/usr/share/doc/R-4.0.2/html/packages.html', reason 'No such file or directory'
3: In make.packages.html(.Library) : cannot update HTML package index

The error is the same one as discussed here , but I was looking for a solution that I could implement during image build (ie an environment var or change to an R config file) that would be persistent for those using the image and installing R packages in the future, allowing them to install with a simple call to install.packages() rather than having to use withr::with_makevars() for every package install.该错误与此处讨论的错误相同,但我正在寻找一种可以在图像构建期间实现的解决方案(即环境变量或更改为 R 配置文件),对于那些使用图像和安装 R 包的人来说,这将是持久的将来,允许他们通过对install.packages()的简单调用进行安装,而不必为每个 package 安装使用withr::with_makevars()

You can set R's config file under $R_HOME/etc/Makeconf (or add a Makevars in the same directory).您可以在$R_HOME/etc/Makeconf下设置 R 的配置文件(或在同一目录中添加 Makevars)。 By default, R_HOME should be in /usr/lib64/R , although you can get it in R by running > R.home() .默认情况下, R_HOME应该在/usr/lib64/R中,尽管您可以通过运行> R.home()在 R 中获取它。

Set CC = gcc -std=c11 (or whatever standard you like), you may also want to set CXX standard similarly.设置CC = gcc -std=c11 (或任何您喜欢的标准),您可能还想类似地设置 CXX 标准。


Technically, you can also change what the gcc binary points to.从技术上讲,您还可以更改 gcc 二进制指向的内容。 I tried this after setting the CFLAGS environment variable failed.我在设置 CFLAGS 环境变量失败后尝试了这个。 For example, you can rename the gcc binary (usually under /usr/bin ) to something like gcc-v4.8.5 .例如,您可以将 gcc 二进制文件(通常在/usr/bin下)重命名为gcc-v4.8.5类的名称。 Then create a file called gcc (with proper exec permissions) in the same folder with the following shell script然后使用以下 shell 脚本在同一文件夹中创建一个名为gcc的文件(具有适当的执行权限)

#!/usr/bin/env bash
gcc-v4.8.5 -std=c99 "$@"

This will work by invoking gcc with that extra parameter but it's not recommended since it will probably break after updates to gcc .这将通过使用该额外参数调用gcc来工作,但不建议这样做,因为它可能会在更新到gcc后中断。 That said, I am not sure what happens to Makevars/Makeconf when R will be updated.也就是说,我不确定在更新 R 时 Makevars/Makeconf 会发生什么。

This shouldn't be a problem if the user runs gcc separately, it just sets the default standard that will be ignored if the user specifies the flag as well (since it will appear later in the command).如果用户单独运行gcc这应该不是问题,它只是设置了默认标准,如果用户也指定了标志,则将被忽略(因为它稍后会出现在命令中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM