I tried to call c++ function from another .cpp file. I used .h header. See below what I did.
I have a f.h file:
#ifndef PACKAGENAME_ADD_H
#define PACKAGENAME_ADD_H
#include <Rcpp.h>
Rcpp::NumericVector f(Rcpp::NumericVector x) ;
#endif
f.cpp file:
#include <Rcpp.h>
using namespace Rcpp;
NumericVector f(NumericVector x) {
return x * 2;
}
g.cpp file:
#include <Rcpp.h>
#include <f.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector g(NumericVector x) {
return f(x);
}
The three files are in the same folder I got this error when I run g.cpp:
Rcpp::sourceCpp('~/g.cpp')
Error in dyn.load("/tmp/Rtmpdu4AWp/sourceCpp-x86_64-pc-linux-gnu-0.12.17/sourcecpp_260f5e1a9ebc/sourceCpp_9.so") : unable to load shared object '/tmp/Rtmpdu4AWp/sourceCpp-x86_64-pc-linux-gnu-0.12.17/sourcecpp_260f5e1a9ebc/sourceCpp_9.so': /tmp/Rtmpdu4AWp/sourceCpp-x86_64-pc-linux-gnu-0.12.17/sourcecpp_260f5e1a9ebc/sourceCpp_9.so: undefined symbol: _Z1fN4Rcpp6VectorILi14ENS_15PreserveStorageEEE
Can someone help me? I work on ubuntu 18.04 and I have R 3.4.4 version.