我对RInside + Rcpp + R + C ++ + Windows故事还很陌生。我试图通过成功编译和运行RInside示例来使事情顺利进行。我设法克服了许多最初的问题(例如this one),最后设法构建了64位RInside示例可执行文件。

我正在运行R的最新版本,RTools的最新版本。我通过运行从源代码构建了RInside和RCPP

install.packages(c("Rcpp","RInside"),type="source")


否则,我只能构建x86二进制文件(无法在64位Windows Server操作系统上运行)。从R控制台,一切正常。以下示例通过,没有任何错误:

body <- '
+ NumericVector xx(x);
+ return wrap( std::accumulate( xx.begin(), xx.end(), 0.0));'
>
> add <- cxxfunction(signature(x = "numeric"), body, plugin = "Rcpp")
cygwin warning:
  MS-DOS style path detected: C:/R-215~1.0/etc/x64/Makeconf
  Preferred POSIX equivalent is: /cygdrive/c/R-215~1.0/etc/x64/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
>
> x <- 1
> y <- 2
> res <- add(c(x, y))
> res
[1] 3
> #[1] 3


但是,当我尝试运行RInside示例时,出现以下错误:

Error in paste0("(^|[^%])(%%)*%", spec) : not a BUILTIN function
Error in paste0("^", pkg, "$") : not a BUILTIN function
Execution halted


有人知道发生了什么吗?

非常感谢。

编辑:
R 2.15.0更详细的发行说明。

我将最新版本从CRAN安装到C:\ R-2.15.0
跑64位RGUI.exe并执行install.packages(c("Rcpp","RInside"),type="source")
更改了Makefile.win以强制使用x64体系结构并指向正确的安装目录。

## -*- mode: makefile; tab-width: 8; -*-
##
## Simple Makefile for Windows

## This version is fairly directly derived from the Unix versions
## You may have to set R_HOME manually if this does not work
## It requires Rtools in the path -- as does all R package building
#R_HOME :=      $(shell R RHOME | sed -e "s|\\\\|\/|g")
R_HOME := "C:\R-2.15.0"
#R_HOME := "C:\R-2.14.1"
#R_HOME := "C:\R-2.14.2"

## You may have to set this to one of the two values to enforce a particular architecture
#R_ARCH :=      --arch i386
R_ARCH :=       --arch x64

sources :=      $(wildcard *.cpp)
programs :=         $(sources:.cpp=)

## include headers and libraries for R
RCPPFLAGS :=        $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config --cppflags)
RLDFLAGS :=         $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config --ldflags)
RBLAS :=        $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config BLAS_LIBS)
RLAPACK :=      $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config LAPACK_LIBS)


## include headers and libraries for Rcpp interface classes
RCPPINCL :=         $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R $(R_ARCH) --vanilla --slave)
RCPPLIBS :=         $(shell echo 'Rcpp:::LdFlags()'  | $(R_HOME)/bin/R $(R_ARCH) --vanilla --slave)


## include headers and libraries for RInside embedding classes
RINSIDEINCL :=      $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R $(R_ARCH) --vanilla --slave)
RINSIDELIBS :=      $(shell echo 'RInside:::LdFlags()'  | $(R_HOME)/bin/R $(R_ARCH) --vanilla --slave)


## compiler etc settings used in default make rules
CXX :=          $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config CXX)
CPPFLAGS :=         -Wall $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config CPPFLAGS)
CXXFLAGS :=         $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config CXXFLAGS)
LDFLAGS =       -s
LDLIBS :=       $(RLDFLAGS) $(RBLAS) $(RLAPACK) $(RINSIDELIBS) $(RCPPLIBS)
CC :=           $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config CXX)


all :           $(programs)


clean:
            rm -vf $(programs)


checkR:
            echo "R is at $(R_HOME)"


跑make -f Makefile.win

cygwin warning:
  MS-DOS style path detected: C:\R-2.15.0/bin/R
  Preferred POSIX equivalent is: /cygdrive/c/R-2.15.0/bin/R
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  atomic.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas -LC:/R-2
.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside.a" C:/R-
2.15.0/library/Rcpp/lib/x64/libRcpp.a -o atomic
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_callbacks0.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRb
las -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRIns
ide.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_callbacks0
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_module_sample0.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64
-lRblas -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/lib
RInside.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_module_sample0
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample0.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample0
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample1.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample1
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample10.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRbla
s -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInsid
e.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample10
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample11.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRbla
s -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInsid
e.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample11
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample2.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample2
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample3.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample3
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample4.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample4
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample5.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample5
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample6.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample6
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample7.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample7
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample8.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample8
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample9.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample9
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_test0.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas -
LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside.a
" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_test0
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_test1.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas -
LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside.a
" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_test1


我有可执行文件,但是当我尝试运行任何可执行文件时,都会出现以下错误。

Error in paste0("(^|[^%])(%%)*%", spec) : not a BUILTIN function
Error in paste0("^", pkg, "$") : not a BUILTIN function
Execution halted

最佳答案

请在rcpp-devel mailing list上发布完整且可复制的示例。请注意,您需要订阅列表上的帖子;否则请使用Gmane subscription to it之类的东西。

自从我们解决了初始化问题以来,RInside绝对可以在Windows下运行。但是,您必须输入make -f Makefile.win,而不仅仅是make。发布具有可复制源的完整命令以及完整的错误日志。

关于c++ - 在Windows下构建(并运行)RInside示例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10636471/

10-09 03:55