我想使用RcppArmadillo
. 正如我在另一篇关于 SO 的文章中所读到的,如果RcppArmadillo.h
包含,Rcpp.h
则不应包含在内。我就是这样做的,但是在尝试编译.cpp
文件时,我收到了一些错误消息。编辑。根据 Dirk 的建议,我只包括RcppArmadillo.h
,这大大减少了错误消息的数量: 最低限度可重现的代码如下:
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
using namespace arma;
template <class RandomAccessIterator, class StrictWeakOrdering>
void sort(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp);
struct val_order{
int order;
double value;
};
bool compare(const val_order & a, const val_order & b){return (a.value<b.value);}
// [[Rcpp::export]]
IntegerVector order(NumericVector x){
int n=x.size();
std::vector<int> output(n);
std::vector<val_order> index(n);
for(int i=0;i<x.size();i++){
index[i].value=x(i);
index[i].order=i;
}
std::sort(index.begin(), index.end(), compare);
for(int i=0;i<x.size();i++){
output[i]=index[i].order;
}
return wrap(output);
}
错误信息如下:
Error in sourceCpp("functions.cpp") :
Error 1 occurred building shared library.
ld: warning: directory not found for option '-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/x86_64'
ld: warning: directory not found for option '-L/usr/local/lib/x86_64'
ld: warning: directory not found for option '-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3'
ld: library not found for -lgfortran
collect2: ld returned 1 exit status
make: *** [sourceCpp_44748.so] Error 1
重申一下,这段代码在我使用Rcpp.h
.