Reputation: 4180
I would like to use some of the functionalities included in RcppArmadillo
. As I read in another post on SO, if RcppArmadillo.h
is included, Rcpp.h
should not be included. I did just that, but when trying to compile the .cpp
file, I got some error messages. EDIT. Per Dirk's suggestion, I only included RcppArmadillo.h
, which significantly reduced the number of error messages: The minimally reproducible code is below:
#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);
}
The error message is below:
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
Just to reiterate, this code has no problem compiling when I use Rcpp.h
.
Upvotes: 1
Views: 642
Reputation: 368509
A few things:
Your post is not helpful. We do not need dozens of lines of error messages, but we do need reproducible code. Which you did not included.
You include several C++ headers and several R headers. Don't.
Include one header only: RcppArmadillo.h and if that fails, post a reproducible example.
Edit: Thanks for your update. Your code now compiles, your error is a linker error. You simply need to install the Fortran compiler under OS X.
Upvotes: 1