[Rcpp-devel] Including a compiled function with inline
Marie Auger-Methe
marie.augermethe at gmail.com
Mon Jun 4 11:19:22 CEST 2012
Hi list,
I am writing a Rcpp function (referred as f2). To be able to debug it, I
am currently using inline to write f2. f2 uses a function that I've
wrote and is now part of a package that I have made (referred as f1). f1
is an Rcpp function that is not called within R but only called from
Rcpp functions. I was wondering how I could use this f1 function within
f2 when using inline. From what I understand I should be able to use the
argument includes from cxxfunction. I think it is related to this thread:
http://thread.gmane.org/gmane.comp.lang.r.rcpp/2593/focus=2600
But I can't quite figure out.
Here is a small example:
library(inline)
library(fxwithinfx) # My package that contain f1
src <- '
using namespace Rcpp;
double y = 9;
NumericVector z(1);
f1(y, z);
z[0] = z[0] + 1;
return z;
'
f2 <- cxxfunction(signature(), body = src, plugin = "Rcpp", includes =
"#include <fxwithinfx/f1.h>")
# I get the following error:
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file11741d6932c4.cpp:19:27: fatal error: fxwithinfx/f1.h: No such file or directory
compilation terminated.
# I tried to change the reference to f1.h by changing the path, but whatever path I give I still get an error. For example, if I use this instead:
f2<- cxxfunction(signature(), body = src, plugin = "Rcpp",
includes = "#include<C:/Users/Marie/Documents/R/fxwithinfx/src/f1.h>")
# I get the following error:
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file11743a6031d8.o:file11743a6031d8.cpp:(.text+0x104): undefined reference to `f1'
collect2: ld returned 1 exit status
# I'm actually not sure whether I should refer the actual .h location or to the location within my R libraries
# Here are the header and src codes for the f1
f1.h:
#ifndef _fxwithinfx_f1_H
#define _fxwithinfx_f1_H
#include<Rcpp.h>
extern "C" int f1(double y, SEXP z) ;
#endif
f1.cpp:
#include "f1.h"
int f1(double y, SEXP z){
using namespace Rcpp;
NumericVector zz(z);
zz[0] = y + 1.5;
}
Any help will be appreciated!
Marie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20120604/ce8ad16b/attachment.html>
More information about the Rcpp-devel
mailing list