【问题标题】:C99 mode error when installing rlang on centos7在centos 7上安装erlang时出现C99模式错误
【发布时间】:2021-03-18 18:31:15
【问题描述】:

我已经创建了一个基于 Centos7 的 docker 镜像,并使用下面的 Dockerfile 安装了 R:

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

我正在尝试安装 R 包 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

该错误与here 讨论的错误相同,但我正在寻找一种可以在图像构建期间实现的解决方案(即环境变量或更改为 R 配置文件),该解决方案对于那些使用映像并在将来安装 R 包,允许它们通过简单的调用 install.packages() 进行安装,而不必为每个包安装使用 withr::with_makevars()

【问题讨论】:

  • 你能用 CentOS8 镜像代替吗?
  • @dbush 不幸的是,由于其他一些依赖项的可用性,我不能(我不知道细节,这正是 SA 告诉我的)。
  • 设置环境变量CFLAGS="-std=c99"有帮助吗?

标签: r c dockerfile centos7 c99


【解决方案1】:

您可以在$R_HOME/etc/Makeconf 下设置R 的配置文件(或在同一目录中添加一个Makevars)。默认情况下,R_HOME 应该在 /usr/lib64/R 中,尽管您可以通过运行 &gt; R.home() 在 R 中获取它。

设置CC = gcc -std=c11(或任何你喜欢的标准),你可能还想设置类似的CXX标准。


从技术上讲,您还可以更改 gcc 二进制文件指向的内容。我在设置 CFLAGS 环境变量失败后尝试了这个。例如,您可以将 gcc 二进制文件(通常在 /usr/bin 下)重命名为 gcc-v4.8.5。然后使用以下 shell 脚本在同一文件夹中创建一个名为 gcc 的文件(具有适当的 exec 权限)

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

这将通过使用该额外参数调用gcc 来工作,但不建议这样做,因为它可能会在更新到gcc 后中断。也就是说,我不确定当 R 更新时 Makevars/Makeconf 会发生什么。

如果用户单独运行gcc,这应该不是问题,它只是设置了默认标准,如果用户也指定了标志将被忽略(因为它会在命令的后面出现)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-09
    • 2016-07-21
    • 2015-09-25
    • 2016-06-05
    • 2014-12-02
    • 2018-12-27
    • 2017-08-30
    相关资源
    最近更新 更多