使用不同的gcc版本从Rtools与Rcpp包括在Windows上 [英] Using a different gcc version from that included with Rtools with Rcpp on Windows
问题描述
在我开始更新gcc之前,有任何人实际尝试过,并且他们可以确认从源代码建立R是更新gcc版本,用于使用Rcpp编译c ++代码(即不一定用于包创作,当然不是为了CRAN有效包)?
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 (i.e. not necessarily for package authoring and certainly not for CRAN-valid packages)?
请参阅Dirk对此问题的回答以及原始海报的后续评论如何在Windows上使用gcc 4.8.1与Rcpp 。
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.
推荐答案
不需要从源重建 R
。这里是我用于 Windows 7 x64
系统的步骤,运行 R 3.1.1
与 Rtools 3.1.0.1942
。此更新对 gcc
的影响尚未彻底测试:
Rebuilding R
from source does not appear necessary. Here are the steps I used for a Windows 7 x64
system, running R 3.1.1
with Rtools 3.1.0.1942
. The implications of this update to gcc
have not been thoroughly tested:
- 启动清除R会话和
remove.packages(Rcpp)
和任何其他Rcpp
相关。关闭R会话。 - 从
- 选择gcc版本4.8.1 / Arch x64 / Threads posix / Exception sjlj / Build rev 5并安装到[云端硬盘]:\Rtools \mingw-builds\ ...
更新系统
PATH
条目(位于PATH
顶部或其附近):[驱动器]:\R\R-3.1.1\ bin \x64; [Drive]:\Rtools\bin; [Drive]:\Rtools \mingw-build\x64-4.8.1-posix-sjlj-rev5\mingw64\bin\;
第三个路径条目替换Rtools
安装程序:[Drive]:\Rtools\gcc-4.6.3\bin
- Start a clean R session and
remove.packages("Rcpp")
and anything elseRcpp
related. Close R session. - Download and run MinGW-builds from Link to MinGW-builds installer.
- Select gcc version 4.8.1/Arch x64/Threads posix/Exception sjlj /Build rev 5 and install to [Drive]:\Rtools\mingw-builds\ ...
Update the system
PATH
variable to include these entries in the following order (at or near the top ofPATH
):[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 theRtools
installer:[Drive]:\Rtools\gcc-4.6.3\bin
重新启动或以其他方式反映PATH
Restart, or otherwise, to reflect PATH changes.
使用 R 3.1.1(2014-07-10)
与 Rcpp 0.11.2
。使用 rgui.exe
而不是通过诸如 RStudio
的IDE来执行此操作最简单,
These steps have been followed using R 3.1.1 (2014-07-10)
with 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.
通过运行 system('gcc -v')$ c $测试设置c>在
R
会话中获取:
Test set-up by running system('gcc -v')
in a R
session to obtain:
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)
要确认 gcc 4.6.3到4.8.0
在 R中有一些新的
C ++ 11
特性 gcc 4.8。*
/ code>会话运行 Rcpp :: sourceCpp
下面的代码,保存为 .cpp
生成没有编译器警告或错误(而这将完全失败使用 gcc 4.6.3
):
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
):
#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_);
}
这篇关于使用不同的gcc版本从Rtools与Rcpp包括在Windows上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!