我试图在这个post中运行Dirk Eddelbuettel提供的colMaxRCpp函数。我只是在这里重复这个功能,以便阅读这篇文章的人不必点击链接。
library(inline)
colMaxRcpp <- cxxfunction(signature(X_="numeric"), plugin="Rcpp", body='
Rcpp::NumericMatrix X(X_);
int n = X.ncol();
Rcpp::NumericVector V(n);
for (int i=0; i<n; i++) {
Rcpp::NumericVector W = X.column(i);
V[i] = *std::max_element(W.begin(), W.end()); // from the STL
}
return(V);
')
当我尝试运行它时,我收到以下错误:
cygwin warning:
MS-DOS style path detected: C:/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf
Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-30~1.2/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
file148253859d1.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in
make: *** [file148253859d1.o] Error 1
ERROR(s) during compilation: source code errors or compiler configuration errors!
Program source:
1:
2: // includes from the plugin
3:
4: #include <Rcpp.h>
5:
6:
7: #ifndef BEGIN_RCPP
8: #define BEGIN_RCPP
9: #endif
10:
11: #ifndef END_RCPP
12: #define END_RCPP
13: #endif
14:
15: using namespace Rcpp;
16:
17:
18: // user includes
19:
20:
21: // declarations
22: extern "C" {
23: SEXP file148253859d1( SEXP X_) ;
24: }
25:
26: // definition
27:
28: SEXP file148253859d1( SEXP X_ ){
29: BEGIN_RCPP
30:
31: Rcpp::NumericMatrix X(X_);
32: int n = X.ncol();
33: Rcpp::NumericVector V(n);
34: for (int i=0;i<n; i++) {
35: Rcpp::NumericVector W=X.column(i);
36: V[i] = *std::max_element(W.begin(),W.end());
37: }
38: return(V);
39:
40: END_RCPP
41: }
42:
43:
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! cygwin warning:
MS-DOS style path detected: C:/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf
Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-30~1.2/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
file148253859d1.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in
make: *** [file148253859d1.o] Error 1
In addition: Warning message:
running command 'C:/PROGRA~1/R/R-30~1.2/bin/x64/R CMD SHLIB file148253859d1.cpp 2>
file148253859d1.cpp.err.txt' had status 1
我无法理解上面的错误消息。我该怎么做才能解决这个错误?感谢。
修改
如果我尝试evalCpp("2+2")
g++ -m64 -I"C:/PROGRA~1/R/R-30~1.2/include" -DNDEBUG -I"C:/Users/Pradipto/Documents/R/win- library/3.0/Rcpp/include" -I"C:/Users/Pradipto/Documents/R/win-library/3.0/Rcpp/include"
-I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c
file1bb87b48650d.cpp -o file1bb87b48650d.o file1bb87b48650d.cpp:1:0: sorry, unimplemented: 64- bit mode not compiled in make: *** [file1bb87b48650d.o] Error 1
Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput, :
Error 1 occurred building shared library.
答案 0 :(得分:1)
这不是代码的问题。使用Rcpp-as-released:
R> source("/tmp/uday.R") ## with your example in this file
R> colMaxRcpp(matrix(1:9,3))
[1] 3 6 9
R>
尝试更简单的方法,例如
R> evalCpp("2 + 2") ## eval expression via C++ program
[1] 4
R> evalCpp("M_PI") ## pi as constant in math.h
[1] 3.14159
R>
看你的编译器没问题。