如何让Rcpp工作?

时间:2014-05-04 16:47:00

标签: r gcc rcpp

我无法让Rcpp在Windows 8.1上运行。当我运行以下最小的示例时,我收到错误。

> library(Rcpp)
> evalCpp("1 + 1")
g++ -m64 -I"C:/R/R-31~1.0/include" -DNDEBUG     -I"C:/R/R-3.1.0/library/Rcpp/include"  -  
I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall  -mtune=core2 -c file11dc2120723d.cpp -o  
file11dc2120723d.o g++: not found make: *** [file11dc2120723d.o] Error 127 Warning message: running
command 'make -f "C:/R/R-31~1.0/etc/x64/Makeconf" -f "C:/R/R-31~1.0/share/make/winshlib.mk"
SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_97232.dll" WIN=64 TCLBIN=64
OBJECTS="file11dc2120723d.o"' had status 2  
Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput,  : 
  Error 1 occurred building shared library.

我路径中的两个第一个条目是:     PATH = C:\ Rtools \ BIN; C:\ Rtools \ GCC-4.6.3 \ BIN;

R安装在目录C:\ R \ R-3.1.0

Rtools位于目录C:\ R \ Rtools

其他一些信息:

> library(devtools)
> find_rtools(T)

Scanning path...
ls : c:\Rtools\bin\ls.exe 
Scanning registry...
Found c:/Rtools for 3.1 
VERSION.txt
Rtools version 3.1.0.1942 
 [1] TRUE

> has_devel()
"C:/R/R-31~1.0/bin/x64/R" --vanilla CMD SHLIB foo.c 

gcc -m64 -I"C:/R/R-31~1.0/include" -DNDEBUG     -I"d:/RCompile/CRANpkg/extralibs64/local/include"     
O2 -Wall  -std=gnu99 -mtune=core2 -c foo.c -o foo.o
gcc: not found
make: *** [foo.o] Error 127
Warning message:
running command 'make -f "C:/R/R-31~1.0/etc/x64/Makeconf" -f "C:/R/R-31~1.0/share/make/winshlib.mk"
SHLIB="foo.dll" WIN=64 TCLBIN=64 OBJECTS="foo.o"' had status 2 
Error: Command failed (1)

> system('g++ -v')
Warning message:
running command 'g++ -v' had status 127 

3 个答案:

答案 0 :(得分:0)

不确定您是否已解决问题,但似乎未安装gcc或g ++。对于Windows,您可以使用MinGW获取这些工具。

  1. 安装可以从here下载的MinGW。信息主页为here

  2. 安装MinGW后,您可以打开'MinGW Installation Manager'并安装bin和dev以获取'mingw32-gcc-g ++'。

  3. 然后必须更新PATH环境变量以包含'C:\ MinGW \ bin'和'C:\ MinGW \ msys \ 1.0 \ bin'。

  4. 重新启动你的R会话,也不会因重新安装'Rcpp'而受伤,并再次尝试require(Rcpp); evalCpp("1 + 1")

答案 1 :(得分:0)

我在尝试直接调用C代码时遇到了这个问题。从功能系统()切换到system2()立即解决了它。

答案 2 :(得分:0)

我通过安装RTools并在路径中添加RBuildTools来解决这个问题:

Sys.setenv("PATH" = paste(Sys.getenv("PATH"),
    "C:\\RBuildTools\\3.4\\bin",
    "C:\\RBuildTools\\3.4\\mingw_32",
    "C:\\RBuildTools\\3.4\\mingw_64", sep = ";"))

我不清楚这些事情,但是@cdeterman解决方案不能用于构建我的包,而它的示例evalCpp("1 + 1")也是如此。