bash 使用备用 GCC 构建 R 包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1616983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 21:19:07  来源:igfitidea点击:

Building R Packages using Alternate GCC

bashgccr

提问by Ryan R. Rosario

The systems I work with have GCC 4.5 (experimental) in /usr/local/bin/gcc which has proven to be problematic for some R packages. I would like to instead use system GCC in /usr/bin/gcc.

我使用的系统在 /usr/local/bin/gcc 中有 GCC 4.5(实验性),这已被证明对某些 R 包有问题。我想在 /usr/bin/gcc 中使用系统 GCC。

I have tried setting CC and CXX in the Bash configuration files (.bashrc, .bash_profile etc.) as well as on the command line, but although Bash recognizes the change, R does not.

我曾尝试在 Bash 配置文件(.bashrc、.bash_profile 等)以及命令行中设置 CC 和 CXX,但尽管 Bash 识别出更改,但 R 不识别。

How can I get R to use the version of GCC in /usr/bin instead of the one in /usr/local/bin/?

如何让 R 使用 /usr/bin 中的 GCC 版本而不是 /usr/local/bin/ 中的版本?

回答by Dirk Eddelbuettel

This is not that well documented (e.g. I failed to locate it in either 'R Extension' or 'R Admin' right now) but Brian Ripley mentioned it a few times on the lists.

这不是很好的文档(例如,我现在无法在“R 扩展”或“R 管理”中找到它)但是 Brian Ripley 在列表中多次提到它。

Basically, at R compile time, settings are registered and the stored in $R_HOME/etc/Makeconf. One possibility is to edit that file directly, but you may not have root privileges or may not want to affect all other users. So the better may be to create

基本上,在 R 编译时,设置被注册并存储在$R_HOME/etc/Makeconf. 一种可能性是直接编辑该文件,但您可能没有 root 权限或可能不想影响所有其他用户。所以更好的可能是创造

~/.R/Makevars

with entries

有条目

CC=gcc-4.4
CXX=g++-4.4

plus whichever optmisation flags etc you want to set. That will the affect all subsequent uses of R CMD INSTALLor R CMD checkor ... that you run.

加上您要设置的任何优化标志等。这将影响您运行的R CMD INSTALLorR CMD check或 ... 的所有后续使用。

Other files in $R_HOME/etc/can similarly be overridden locally from ~/.R/.

中的其他文件$R_HOME/etc/同样可以从~/.R/.

回答by Gil Hornung

I had a very similar problem.

我有一个非常相似的问题。

What worked for me was to define a project directory (rstudio can do that for you), and then add a .Renvironfile that modifies the PATH and LD_LIBRARY_PATH, to include the directory with the new gcc. In your case, for example, the .Renvironwill look something like:

对我有用的是定义一个项目目录(rstudio 可以为您完成),然后添加一个.Renviron修改 PATH 和 LD_LIBRARY_PATH的文件,以将目录包含在新的 gcc 中。例如,在您的情况下,.Renviron将类似于:

LD_LIBRARY_PATH=/usr/local/bin/gcc/lib:/usr/local/bin/gcc/lib64:/usr/local/bin/gcc/libexec:other paths

LD_LIBRARY_PATH=/usr/local/bin/gcc/lib:/usr/local/bin/gcc/lib64:/usr/local/bin/gcc/libexec:其他路径

PATH=/usr/local/bin/gcc/bin:/usr/local/bin:other paths

PATH=/usr/local/bin/gcc/bin:/usr/local/bin:其他路径

回答by R Samuel Klatchko

Check your path to see if /usr/local/bin comes before /usr/bin. If it does, just make sure /usr/bin comes first:

检查您的路径以查看 /usr/local/bin 是否在 /usr/bin 之前。如果是这样,只需确保 /usr/bin 排在第一位:

PATH=/usr/bin:${PATH}

(it's okay if /usr/bin is duplicated appears twice).

(如果 /usr/bin 重复出现两次也没关系)。

回答by isomorphismes

Look at configure.argspart of ?install.packagesand compare this to ./configure --helpon e.g. the r source tree.

查看configure.args一部分?install.packages并将其与./configure --help例如 r 源代码树进行比较。

You can also, from bash, CC=clang R CMD INSTALL /path/to/package/source.

您也可以从 bash 中,CC=clang R CMD INSTALL /path/to/package/source.

HTH

HTH