编译器错误:使用Rccp类时架构x86_6的未定义符号。

时间:2015-08-28 17:35:08

标签: c++ r rcpp

我刚刚习惯使用R中的Rcpp包。我通常在使用Rcpp时构建一个包。但是,要进行调试和测试,我希望能够在不涉及R的情况下运行c ++代码。因此,我尝试在c ++程序中使用Rccp类。例子

#include <Rcpp.h>

int main(int argc, const char * argv[])
{
    Rcpp::NumericVector vec(0);

    return 0;
}

产生以下错误:

Undefined symbols for architecture x86_64:
  "_REprintf", referenced from:
      Rcpp::Rstreambuf<false>::xsputn(char const*, long) in main-fe5efc.o
      Rcpp::Rstreambuf<false>::overflow(int) in main-fe5efc.o
  "_R_FlushConsole", referenced from:
      Rcpp::Rstreambuf<false>::sync() in main-fe5efc.o
      Rcpp::Rstreambuf<true>::sync() in main-fe5efc.o
  "_R_GetCCallable", referenced from:
      dataptr(SEXPREC*) in main-fe5efc.o
  "_R_NilValue", referenced from:
      Rcpp::PreserveStorage<Rcpp::Vector<14, Rcpp::PreserveStorage> >::PreserveStorage() in main-fe5efc.o
      Rcpp::PreserveStorage<Rcpp::Vector<14, Rcpp::PreserveStorage> >::~PreserveStorage() in main-fe5efc.o
      Rcpp::Rcpp_ReleaseObject(SEXPREC*) in main-fe5efc.o
      Rcpp::Rcpp_PreserveObject(SEXPREC*) in main-fe5efc.o
  "_R_PreserveObject", referenced from:
      Rcpp::Rcpp_PreserveObject(SEXPREC*) in main-fe5efc.o
  "_R_ReleaseObject", referenced from:
      Rcpp::Rcpp_ReleaseObject(SEXPREC*) in main-fe5efc.o
  "_Rf_allocVector", referenced from:
      Rcpp::Vector<14, Rcpp::PreserveStorage>::Vector(int const&) in main-fe5efc.o
  "_Rf_isNull", referenced from:
      Rcpp::Rcpp_ReplaceObject(SEXPREC*, SEXPREC*) in main-fe5efc.o
  "_Rf_xlength", referenced from:
      void Rcpp::internal::r_init_vector<14>(SEXPREC*) in main-fe5efc.o
  "_Rprintf", referenced from:
      Rcpp::Rstreambuf<true>::xsputn(char const*, long) in main-fe5efc.o
      Rcpp::Rstreambuf<true>::overflow(int) in main-fe5efc.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我使用以下命令编译:

clang++ main.cpp -I/Library/Frameworks/R.framework/Resources/include -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include"

我在Mac上使用Xcode 6.寻找解决方案我已经从源代码安装了Rcpp和RInside,但它没有解决问题。感谢任何帮助!

1 个答案:

答案 0 :(得分:3)

Rcpp是R扩展名。没有R.它就无法工作。

你只是做了一个英勇的假设,你可以做你正在做的事情。结果证明这个假设不正确。

你最接近的赌注,你想要建立新的“主要”程序,就是使用RInside嵌入R.开始时有很多例子,特别是examples/standard/