Para2x
Para2x

Reputation: 61

Rcpp - Compile a C++ file with multiple functions

I have just quick question about how to compile a .cpp file with multiple function in it. Let's say I have c++ file like this : Functions.cpp

#include <Rcpp.h>
#include <math.h>       /* pow */
using namespace Rcpp;

 // [[Rcpp::export]]
 int Function1 (int N, NumericMatrix W){
 return ....
  }

 // [[Rcpp::export]]
 int Function2 (int N, NumericMatrix W){
 return ....
  }

and then I would like to compile the file and be able to to call both functions. I have done it, but what happens is when I try to load the Functions.o it gives me this":

 Error in inDL(x, as.logical(local), as.logical(now), ...) : 
unable to load shared object 'C:/Users/Functions.o': 
 LoadLibrary failure:  %1 is not a valid Win32 application.

Anybody , any idea ?

Upvotes: 1

Views: 1026

Answers (1)

Dirk is no longer here
Dirk is no longer here

Reputation: 368231

Just use sourceCpp("nameofyourfile.cpp")

If you you have no syntax error preventing compilation both Function1 and Function2 will be accessible in your R session.

Literally thousands of such files have been written, and almost one hundred are at your disposal over at the Rcpp Gallery.

Upvotes: 4

Related Questions