c++ - 无法在 RStudio 中使用头文件编译 RcppArmadillo 脚本
问题描述
我有一个 Rcpp 脚本,它由两个文件组成,一个main.cpp
包含主函数,另一个functions.cpp
文件包含在主函数中调用的一些其他函数。
main.cpp
:
#include "functions.h"
// [[Rcpp::export]]
... some function
头文件functions.h
#ifndef FUN_H
#define FUN_H
#include <RcppArmadillo.h>
double pmvnormArma(int n, const arma::mat& Sigma ) ;
#endif
和包含函数的脚本:functions.cpp
double pmvnormArma(int n, const arma::mat& Sigma)
{
...
return(p) ;
}
我通常使用“源”按钮从 RStudio 编译我的 Rcpp 脚本。但是,当我将脚本分成多个文件时,如上所述,我得到一个错误:
make: *** No rule to make target 'p2/rcpp/prova/functions.o', needed by 'sourceCpp_4.so'. Stop.
Error in Rcpp::sourceCpp("main.cpp") :
Error 1 occurred building shared library.
然后我尝试直接从终端编译代码,但是,由于我在 R 中安装了 Rcpp,编译器找不到所需的库:
$ g++ -c -o functions.o functions.cpp
functions.cpp:2:10: fatal error: RcppArmadillo.h: No such file or directory
2 | #include <RcppArmadillo.h>
| ^~~~~~~~~~~~~~~~~
compilation terminated.
即使我包含了犰狳的路径,我也会获得其他库(RcppCommon.h、Rh 等)丢失文件的新消息。我怎么解决这个问题?有没有一种简单的方法可以从 RStudio 编译大型项目,或者将 g++ 编译器链接到所有需要的包(位于 R 文件夹中)?
解决方案
推荐阅读
- java - 如何按顺序而不是一次更改 JavaFx 图像?
- javascript - Update the email verification status without reloading page
- kotlin - DisposableObserver<> 不是 Observer<> 的子类型
- python-3.x - Python单元测试嵌套“异步”,如何模拟/修补?
- excel - 如何显示超过 x 个非空行的列
- java - How to put an lwjgl app into a Javafx/swing canvas
- excel - Specifying criteria as named range in Excel
- angular - Angular 6 kendo-dropdownlist ERROR TypeError:无法读取未定义的属性“值”
- javascript - Google Maps API 信息窗口在 iOS 12 上不垂直滚动
- webpack - 如何在 index.html 模板中引用图片资源