2014-01-16 24 views
5

我得到以下奇怪的錯誤給奇怪的編譯錯誤:sourceCpp從RCPP上典型的例子

> sourceCpp("comp.Cpp") 
Warning message: 
In sourceCpp("comp.Cpp") : 
No Rcpp::export attributes or RCPP_MODULE declarations found in source 
當我使用sourceCpp

。該「comp.Cpp」文件是這樣的:

#include <Rcpp.h> 

using namespace Rcpp; 

// [[Rcpp:export]] 
RcppExport SEXP comp(int n){ 
    int i; 
    Rcpp::NumericVector product(n); 
    for(i=0;i<n;i++){ 
     product[i]=i; 
    } 
    return(product); 
} 

我試圖更新我的操作系統小牛(然後不得不重新安裝的Xcode命令行工具和一些其他的東西),但這個錯誤是早。我可以製作測試軟件包並安裝它並運行它提供的hello world,因此Rcpp軟件包大部分工作正常。我也從R中運行得到另一個錯誤:

cppFunction(" 
    int useCpp11() { 
     auto x = 10; 
     return x; 
    } 
", plugins=c("cpp11")) 

這是

llvm-g++-4.2 -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include  -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include" -std=c++11 -fPIC -mtune=core2 -O3 -c file69810a85a0d.cpp -o file69810a85a0d.o 
Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput, : 
    Error 1 occurred building shared library. 
cc1plus: error: unrecognized command line option "-std=c++11" 
make: *** [file69810a85a0d.o] Error 1 

我不知道這兩件事情有關。我認爲我的編譯器不能很好地處理屬性,但是在網上搜索並沒有讓我充分理解這一點。

任何幫助將不勝感激。

回答

7

通過「[[Rcpp :: export]]」更改「[[Rcpp:export]]」「。

#include <Rcpp.h> 

using namespace Rcpp; 

// [[Rcpp::export]] 
SEXP comp(int n){ 
    int i; 
    Rcpp::NumericVector product(n); 
    for(i=0;i<n;i++){ 
     product[i]=i; 
    } 
    return(product); 
} 
+1

雖然它不是OP的意圖,但它並未影響編譯及其失敗。您的修復將幫助將函數連接到R,但它並不能幫助gcc 4.2太舊。 –

3

您的編譯器對於C++ 11標誌來說太舊了。錯誤信息非常清楚。

嘗試-std=c++0x以及升級到Xcode 5(它有自己的一套問題 - 但這些都在這裏很好地記錄)。

+1

謝謝。儘管如此,我很抱歉地說我仍然不明白這個錯誤意味着我已經過時了。 – miratrix