包内联的 cxxfunction 的问题 [英] issue with cxxfunction of package inline

查看:37
本文介绍了包内联的 cxxfunction 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在这个 发布.我只是在这里重复这个功能,这样阅读这篇文章的人就不必点击链接了.

I was trying to run the colMaxRCpp function provided by Dirk Eddelbuettel in this post. I'm just repeating the function here so that folks reading this post don't have to click on the link.

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);
 ')

当我尝试运行它时,出现以下错误:

When I tried to run it, I got the following error:

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 

我无法理解上面的错误消息.我能做些什么来修复这个错误?谢谢.

I can't understand the error message above. What can I do to fix this error? Thanks.

这是错误,如果我尝试 evalCpp("2+2")

This is the error if I try 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.

推荐答案

这不是代码的问题.使用 Rcpp-as-released:

It's not an issue with the code. Using 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>

尝试一些更简单的东西,比如

Try something simpler such as

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> 

看看你的编译器是否正常.

to see that your compiler is fine.

这篇关于包内联的 cxxfunction 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆