1
我一直在試圖使用Rcpp包將我的一些c/C++代碼的功能擴展到R中。如何在R中包含和鏈接sourceCpp Rcpp
但我在與包含頭文件的問題和聯繫
我做了下面的例子,說明我的問題:
- 我有由.H的原始C程序文件和.c文件
headerfile:add.h
int add(int a,int b);
的CFile:add.c
int add(int a,int b){
return a+b;
}
- C++函數的 '接口',應與功能性連接我的電話[R在我的C文件
monkey.cpp
#include <cstdio>
#include <Rcpp.h>
#include "add.h"
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector monkey(std::string string1,std::string string2) {
//below not important
NumericVector rary(5);
for(int i=0;i<5;i++)
rary[i] = i;
return rary;
}
- 試圖使用「猴子」功能的Rcode
monkey.R
nam1 <- "nam1"
nam2 <- "nam2"
Rcpp::sourceCpp("monkey.cpp")
monkey(nam1,nam2)
Q1。是否可以使用sourceCpp函數爲gcc編譯指定-I標誌?
q2。如果我的接口cpp文件依賴於其他.o文件,是否可以使用sourceCpp函數與這些文件進行鏈接?
好超,謝謝你的幫助。 – user3194934