I've been trying to extend the functionality of some of my c/c++ code into R using the Rcpp package.
But I'm having problems with the inclusion of headers and linking
I've made the following example that illustrates my problem:
- I have a raw c program consisting of a .h file and and .c file
headerfile: add.h
int add(int a,int b);
cfile: add.c
int add(int a,int b){
return a+b;
}
- An 'interface' c++ function that should connect my R call with the functionality in my c file
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;
}
- The Rcode that tries to use the 'monkey' function
monkey.R
nam1 <- "nam1"
nam2 <- "nam2"
Rcpp::sourceCpp("monkey.cpp")
monkey(nam1,nam2)
q1. Is it possible to specify -I flags for the gcc compilation with the sourceCpp function?
q2. If my interface cpp file is dependant on other .o files, is it possible to link with these using the sourceCpp function?