[英]Using a different gcc version from that included with Rtools with Rcpp on Windows
Before I embark on updating gcc, has anyone actually attempted this, and can they confirm building R from source is required to update the gcc version one uses to compile c++ code with Rcpp (ie not necessarily for package authoring and certainly not for CRAN-valid packages)?在我开始更新 gcc 之前,有没有人实际尝试过这个,他们能否确认需要从源代码构建 R 来更新用于使用 Rcpp 编译 c++ 代码的 gcc 版本(即不一定用于包创作,当然也不适用于 CRAN-valid包)?
See Dirk's answer to this question, and the follow-on comment from the original poster How to use gcc 4.8.1 with Rcpp on Windows .请参阅 Dirk 对此问题的回答,以及来自原始海报How to use gcc 4.8.1 with Rcpp on Windows的后续评论。
Rebuilding R
from source does not appear necessary.从源代码重建
R
似乎没有必要。 Here are the steps I used for a Windows 7 x64
system, running R 3.1.1
with Rtools 3.1.0.1942
.以下是我用于
Windows 7 x64
系统的步骤,运行R 3.1.1
和Rtools 3.1.0.1942
。 The implications of this update to gcc
have not been thoroughly tested:此更新对
gcc
的影响尚未经过彻底测试:
remove.packages("Rcpp")
and anything else Rcpp
related.remove.packages("Rcpp")
和任何其他Rcpp
相关的东西。 Close R session. Update the system PATH
variable to include these entries in the following order (at or near the top of PATH
): [Drive]:\\R\\R-3.1.1\\bin\\x64;[Drive]:\\Rtools\\bin;[Drive]:\\Rtools\\mingw-build\\x64-4.8.1-posix-sjlj-rev5\\mingw64\\bin\\;
更新系统
PATH
变量以按以下顺序包含这些条目(在PATH
顶部或附近): [Drive]:\\R\\R-3.1.1\\bin\\x64;[Drive]:\\Rtools\\bin;[Drive]:\\Rtools\\mingw-build\\x64-4.8.1-posix-sjlj-rev5\\mingw64\\bin\\;
the 3rd path entry replaces the one included by the Rtools
installer: [Drive]:\\Rtools\\gcc-4.6.3\\bin
第三个路径条目替换了
Rtools
安装程序中包含的Rtools
: [Drive]:\\Rtools\\gcc-4.6.3\\bin
Restart, or otherwise, to reflect PATH changes.重新启动或以其他方式反映 PATH 更改。
R
session and run install.packages("Rcpp")
and repeat for all the other packages that were removed in step 1.R
会话并运行install.packages("Rcpp")
并对步骤 1 中删除的所有其他包重复此操作。 These steps have been followed using R 3.1.1 (2014-07-10)
with Rcpp 0.11.2
.使用
R 3.1.1 (2014-07-10)
和Rcpp 0.11.2
遵循这些步骤。 It is easiest to do this using rgui.exe
, and not via an IDE such as RStudio
, due to the silent loading of previous workspaces and packages of the latter.使用
rgui.exe
最容易做到这rgui.exe
,而不是通过RStudio
的 IDE,因为它会静默加载以前的工作区和后者的包。
Test set-up by running system('gcc -v')
in a R
session to obtain:通过在
R
会话中运行system('gcc -v')
来测试设置以获得:
COLLECT_GCC=F:\Rtools\MINGW-~1\X64-48~1.1-P\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=f:/rtools/mingw-~1/x64-48~1.1-p/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.1/lto-wrapper.exe
Target: x86_64-w64-mingw32
[Edited Config info]
Thread model: posix
gcc version 4.8.1 (rev5, Built by MinGW-W64 project)
To confirm a selection of compiler bugs present with gcc 4.6.3 to 4.8.0
are no more, as well as test some new C++11
features available with gcc 4.8.*
, in a R
session running Rcpp::sourceCpp
on the following code, saved as .cpp
file, should generate no compiler warnings or errors (whereas this will totally fail using gcc 4.6.3
):为了确认
gcc 4.6.3 to 4.8.0
中存在的编译器错误的选择不再存在,并在运行Rcpp::sourceCpp
的R
会话中测试gcc 4.8.*
可用的一些新的C++11
功能gcc 4.8.*
以下代码保存为.cpp
文件,应该不会产生编译器警告或错误(而使用gcc 4.6.3
这将完全失败):
#include <Rcpp.h>
// [[Rcpp::plugins("cpp11")]]
template<typename T>
struct Wrap
{
int test2(int depth)
{
m_test++;
std::vector<int> v = { 0, 1, 2, 3 };
return depth == 0? 1 : std::accumulate(
v.begin(), v.end(), int(0), [=](int sub, int const&) {
return sub + test2(depth - 1);
});
}
int m_test = 0;
};
struct X
{
template <class T> static void bar() {}
template <class T> void foo(T p)
{
[&] { bar<T>(); };
}
};
// [[Rcpp::export]]
double inheriting(int in_){
struct A {
A(int u){
hello = u*u/2.0;
};
double hello;
};
struct B: A { using A::A; };
B b(in_);
return(b.hello);
}
// [[Rcpp::export]]
void test_lambda(int in_)
{
X x;
x.foo(in_);
}
// [[Rcpp::export]]
int test_bug_4_7_2(int in_){
Wrap<int> w;
return w.test2(in_);
}
Here I describe how we can use GCC v8.1.0 with Rtools to compile source packages in R.在这里,我描述了我们如何使用GCC v8.1.0和 Rtools 来编译 R 中的源包。
This is tested on Windows 10 64 bit Home edition with R v3.5.0 and Rtools35 .这是在带有R v3.5.0和Rtools35 的Windows 10 64 位家庭版上测试的。
C:\\Rtools
.C:\\Rtools
。 You will see following subfolders inside Rtools
:Rtools
看到以下子文件夹:Rtools
is in path by editing environment variable as below:Rtools
在路径中,如下所示:mingw_64
subfolder inside Rtools
.mingw_64
子文件夹中存在的任何Rtools
。 Install in its default location.安装在其默认位置。 Note that by default, it will get installed in
MinGW\\
folder.请注意,默认情况下,它将安装在
MinGW\\
文件夹中。 Copy/Cut whatever is inside this MinGW\\
folder.复制/剪切无论是这里面
MinGW\\
文件夹中。
mingw_64
subfolder inside Rtools
and paste whatever been copied/cut in step 5. After pasting you will see this 👇 inside mingw_64
sub-folder:mingw_64
子文件夹内Rtools
并粘贴在步骤5中任何被复制/粘贴切,你会看到这里面👇后mingw_64
子文件夹: Test your setup to compile C/C++ code in R package rdatatable
with following lines in R
console:测试您的设置以在 R 包
rdatatable
编译 C/C++ 代码,在R
控制台中使用以下几行:
remove.packages("data.table") install.packages("data.table", type = "source", repos = "http://Rdatatable.github.io/data.table")
If successful, you will find something like this:如果成功,您会发现如下内容:
It compiles Rcpp
from source too !它
Rcpp
从源代码编译Rcpp
!
It can compile all R packages
with compiled code, except those with dependencies on external libraries.它可以使用编译后的代码编译所有
R packages
,但依赖于外部库的R packages
除外。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.