簡體   English   中英

centos7上安裝rlang時出現C99模式錯誤

[英]C99 mode error when installing rlang on centos7

我創建了一個基於 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

我正在嘗試安裝 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

該錯誤與此處討論的錯誤相同,但我正在尋找一種可以在圖像構建期間實現的解決方案(即環境變量或更改為 R 配置文件),對於那些使用圖像和安裝 R 包的人來說,這將是持久的將來,允許他們通過對install.packages()的簡單調用進行安裝,而不必為每個 package 安裝使用withr::with_makevars()

您可以在$R_HOME/etc/Makeconf下設置 R 的配置文件(或在同一目錄中添加 Makevars)。 默認情況下, R_HOME應該在/usr/lib64/R中,盡管您可以通過運行> R.home()在 R 中獲取它。

設置CC = gcc -std=c11 (或任何您喜歡的標准),您可能還想類似地設置 CXX 標准。


從技術上講,您還可以更改 gcc 二進制指向的內容。 我在設置 CFLAGS 環境變量失敗后嘗試了這個。 例如,您可以將 gcc 二進制文件(通常在/usr/bin下)重命名為gcc-v4.8.5類的名稱。 然后使用以下 shell 腳本在同一文件夾中創建一個名為gcc的文件(具有適當的執行權限)

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

這將通過使用該額外參數調用gcc來工作,但不建議這樣做,因為它可能會在更新到gcc后中斷。 也就是說,我不確定在更新 R 時 Makevars/Makeconf 會發生什么。

如果用戶單獨運行gcc這應該不是問題,它只是設置了默認標准,如果用戶也指定了標志,則將被忽略(因為它稍后會出現在命令中)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM