r
  • rcpp
  • 2013-12-24 109 views 0 likes 
    0

    問題我試圖在post中運行Dirk Eddelbuettel提供的colMaxRCpp函數。我只是在這裏重複這個功能,讓閱讀這篇文章的人不必點擊鏈接。cxxfunction in package

    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. 
    

    回答

    1

    這不是與代碼的問題。使用RCPP-作爲發佈:

    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> 
    

    看到你的編譯器是好的。

    +0

    evalCpp(「2 + 2」)不起作用。看到上面的錯誤。 – uday

    +1

    也許問題出在「抱歉,未實現:未編譯成make的64位模式」 - 這似乎是兩個處理之間的常見錯誤。 – uday

    +0

    您需要重新審視Rtools的安裝,設置'$ PATH'等pp。 –

    相關問題