包含RcppArmadillo.h后,编译代码时会出错

时间:2013-05-20 05:05:57

标签: r rcpp

我想使用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时,此代码编译没有问题。

1 个答案:

答案 0 :(得分:1)

一些事情:

  1. 您的帖子没有帮助。我们不需要几十行错误消息,但我们确实需要可重现的代码。你未包含的内容。

  2. 您包含多个C ++标头多个R标头。别。

  3. 仅包含一个标题:RcppArmadillo.h如果失败,请发布一个可重现的示例。

  4. 编辑:感谢您的更新。您的代码现在编译,您的错误是链接器错误。您只需要在OS X下安装Fortran编译器。

相关问题