2014-02-06 55 views
0

我是C++和包Rccp的新手,但我在rcpp的庫中找到了一些代碼,可以從多元正態分佈中生成代碼。該代碼是嘗試使用R中的sourceCpp進行編譯時出錯

#include <RcppArmadillo.h> 
// [[Rcpp::depends(RcppArmadillo)]] 

using namespace Rcpp; 

// [[Rcpp::export]] 
arma::mat mvrnormArma(int n, arma::vec mu, arma::mat sigma) { 
    int ncols = sigma.n_cols; 
    arma::mat Y = arma::randn(n, ncols); 
    return arma::repmat(mu, 1, n).t() + Y * arma::chol(sigma); 
} 

其保存在文件multivgaussian.cpp,當我嘗試用

sourceCpp("multivgaussian.cpp") 

我收到此錯誤信息

Error in dyn.load("/tmp/RtmpGoFAwi/sourcecpp_6a751b6a3bee/sourceCpp_67198.so") : 
    unable to load shared object '/tmp/RtmpGoFAwi/sourcecpp_6a751b6a3bee/sourceCpp_67198.so': 
    /tmp/RtmpGoFAwi/sourcecpp_6a751b6a3bee/sourceCpp_67198.so: undefined symbol: _ZN4Rcpp8internal14r_vector_startILi13EEEPNS_6traits12storage_typeIXT_EE4typeEP7SEXPREC 

我也試着編譯R中看看會發生什麼(在終端中),如果我試圖編譯它。

R CMD SHLIB multivgaussian.cpp 
g++ -I/maths/R/lib64/R/include -DNDEBUG -I/usr/local/include -fpic -g -O2 -c multivgaussian.cpp -o multivgaussian.o 
multivgaussian.cpp:1:27: error: RcppArmadillo.h: No such file or directory 
multivgaussian.cpp:4: error: ‘Rcpp’ is not a namespace-name 
multivgaussian.cpp:4: error: expected namespace-name before ‘;’ token 
multivgaussian.cpp:7: error: ‘arma’ has not been declared 
multivgaussian.cpp:7: error: expected constructor, destructor, or type conversion before ‘mvrnormArma’ 
make: *** [multivgaussian.o] Error 1 

這可能是簡單的東西,但我在網上找不到任何東西。非常感謝, Charis

回答

0

Rcpp本週發佈了一個版本,要求重建其用戶軟件包。確保你的RcppArmadillo也被重建了。

在您的R CMD SHLIB示例中,您不告訴R關於RcppArmadillo依賴關係,因此它無法工作。在第一個例子行

// [[Rcpp::depends(RcppArmadillo)]] 

照顧的那個,但你仍然有你的連接問題 - 可能是由於版本不匹配。

+0

感謝您的快速回復(@suspectus,@DirkEddelbuettel)我剛剛發現了Rcpp的新版本,我必須更新R的版本才能安裝新的軟件包。我想這就是它。我必須等到明天大學纔會更新我的R版。再次感謝。 –

+0

你不需要。如果你有一致的版本,那麼它應該工作。只是不更新​​RcppArmadillo和Rcpp之一,但不更新其中之一。 –

+0

剛剛做到了。現在一切似乎都很好。謝謝。 –

相關問題