我有以下目录结构
my_func
- my_func_r.cpp
- my_func.c
- my_func.h
- my_func_test.c
- matrix/
- matrix.h
- matrix.c
The matrix
目录包含一些矩阵结构matrix.h
以及一些初始化、免费、打印等功能matrix.c
. The my_func.h
文件是这样的
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "matrix/matrix.h"
... some structures and templates ...
The my_func.c
文件然后是
#include "my_func.h"
... helper functions ...
int my_func(...) {
... my_func stuff ...
return 0;
}
The my_func_test.c
是这样的
#include "my_func.h"
int main() {
... some test ...
return 0;
}
With gcc/g++
我可以运行这个罚款
gcc my_func_test.c my_func.c matrix/matrix.c -o test -lm
最终文件my_func_r.cpp
是一个接口之间的Rcpp
结构和所使用的结构my_func.c
。目前是这样的
#include "my_func.h"
#include <Rcpp.h>
// [[Rcpp::export]]
int my_func_r(Rcpp::List x, ...) {
... convert inputs to structure recognised by my_func.h ...
... run my_func.c ...
... put returned objects back into one of the R structure ...
return 0;
}
我遇到的问题是如果我现在跑
sourceCpp('my_func_r.cpp', verbose=TRUE, rebuild=TRUE)
它抱怨位于以下位置的函数缺少符号matrix/matrix.c
。解决方法是简单地粘贴我的所有标题和源代码my_func
and matrix
文件位于顶部my_func_r.cpp
.
然而,这感觉是一个非常不令人满意的解决方案,特别是对于代码维护而言。完成我想做的事情的最简单方法是什么?