我有以下目录结构
my_func
- my_func_r.cpp
- my_func.c
- my_func.h
- my_func_test.c
- matrix/
- matrix.h
- matrix.c
matrix
目录包含matrix.h
中的一些矩阵结构以及matrix.c
中的一些初始化,免费,打印等功能。 my_func.h
文件类似于
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "matrix/matrix.h"
... some structures and templates ...
my_func.c
文件是
#include "my_func.h"
... helper functions ...
int my_func(...) {
... my_func stuff ...
return 0;
}
my_func_test.c
就像是
#include "my_func.h"
int main() {
... some test ...
return 0;
}
使用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
顶部的matrix
和my_func_r.cpp
文件中的所有标头和源代码。
答案 0 :(得分:4)
快速的:
src/
目录。libmatrix.a
并链接到该目录。这可以通过简单的src/Makevars
来实现,但仍然不鼓励。请继续阅读。matrix.h
和matrix.c
复制到src/
,调整包含路径,即可完成。sourceCpp()
。它是不,