r - fatal error : RcppEigen. h:没有这样的文件或目录

标签 r rcpp

我对 Rcpp 很陌生和 RcppEigen可能这就是我自己无法弄清楚的原因:

我只想编写一个包含 Eigen 库的 C++ 函数。为了测试它是否有效,我从 http://people.math.aau.dk/~sorenh/misc/Rdocs/Rcpp/RcppSHLIB.pdf 中获取了以下示例:

#include <Rcpp.h>
#include <RcppEigen.h>
RcppExport SEXP C_spdinv_eigen ( SEXP X_ ){
using Eigen::Map;
using Eigen::MatrixXd;
typedef Eigen::Map<Eigen::MatrixXd> MapMatd;
const MapMatd X(Rcpp::as<MapMatd>(X_));
const MatrixXd Xinv(X.inverse());
return(Rcpp::wrap(Xinv));
}

但我收到以下错误:
rcpp-test.cpp:2:23: fatal error: RcppEigen.h: No such file or directory
compilation terminated.
make: *** [rcpp-test.o] Error 1
g++ -I/usr/share/R/include -DNDEBUG    -I"/usr/local/lib/R/site-library/Rcpp/include"    -fpic  -O3 -pipe  -g  -c rcpp-test.cpp -o rcpp-test.o 
Error in Rcpp::sourceCpp("rcpp-test.cpp") : 
  Error 1 occurred building shared library.

编译一个只有 #include <Rcpp.h> 的脚本工作正常。RcppEigen.h -file 位于 /usr/local/lib/R/site-library/RcppEigen/include目录。我尝试安装 RcppEigenR CMD INSTALL ...install.package : 都没有用。

我的 secionInfo 是
R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C         LC_TIME=C            LC_COLLATE=C         LC_MONETARY=C       
 [6] LC_MESSAGES=C        LC_PAPER=C           LC_NAME=C            LC_ADDRESS=C         LC_TELEPHONE=C      
[11] LC_MEASUREMENT=C     LC_IDENTIFICATION=C 

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RcppEigen_0.3.2.1.1 Rcpp_0.11.1        

loaded via a namespace (and not attached):
[1] Matrix_1.1-1.1  grid_3.0.2      lattice_0.20-27 tools_3.0.2    

谢谢你的帮助!

最佳答案

你没说怎么样你试图编译你的函数。这很重要:

  • 在一个包中,使用 LinkingTo: RcppEigen .
  • 在与 Rcpp 属性一起使用的函数中,使用适当的 Rcpp::depends(RcppEigen) .

  • 这里有很多例子,在 Rcpp Gallery和其他地方。遵循它们,但要遵循所有步骤。现在你有编译器告诉你 RcppEigen未知。

    我的 Rcpp book详细构建问题在第 2 章。

    关于r - fatal error : RcppEigen. h:没有这样的文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22596370/

    相关文章:

    r - 有效地将两列 data.table 转换为列表

    c++ - 在 Rcpp 中使用 3rd 方头文件

    r - 在 Rcpp 中生成多元高斯分布

    multithreading - 使用 Rcpp 时抛出错误的线程安全方法是什么

    c++ - 在 Windows 上使用与 Rtools 和 Rcpp 包含的版本不同的 gcc 版本

    c++ - Rcpp降序排序

    r - 使用 R 快速计算子集

    R 错误 : "New Column would leave holes after existing columns"

    r - 如何比较 R 中两个单独数据框的列名?

    r - XLConnect 中的错误