Hi, I would like to embed the LibMesh library in R. I have already linked C++ code and build libraries as it is explained in the R-extension manual with trivial examples : dyn.load(paste("/home/default/LibFooR",.Platform$dynlib.ext,sep="")) I am facing a difficulty with loading a library depending on a library (libMesh) which needs an initialization function (libMesh::init(argc, argv);). Conventionally, the way to make a bridge between R and C is : ___________________________________ extern "C" { void foo_R(double* output, double* S, double* K){ *output = foo(*S,*K,*r,*sigma,*time); }; } ___________________________________ This way, it doesn't seem possible to put arguments argc and argv. To go further and link LibMesh, an "int main( int argc, char** argv )" might have to be specified during the launching of R. May be the ".First.lib" and the "library.dynam" load functions are necessary. But, even that way I am not able to perform the link. At the moment, segmentation fault is still the result with fake argc and argv. If anyone has elements to proceed and implement "init(argc, argv)", it would be great, Thanks, Maxime
Dirk Eddelbuettel
2008-Dec-10 20:42 UTC
[R] Linking a library with init(argc,argv) function
On Wed, Dec 10, 2008 at 09:12:12PM +0100, Maxime Debon wrote:> I am facing a difficulty with loading a library depending on a library > (libMesh) which needs an initialization function (libMesh::init(argc, > argv);).Create 'fake' argc/argv as eg in char *myargv[] = { "somename", "--foo", "--bar"}; int myargc = (sizeof(myargv) - sizeof(myargv) ) / sizeof(myargv[0]); init(myargc, myargv); obviously, --foo and --bar need to be supported by the library in question. Else just do char *myargv[] = { "somename" };> Conventionally, the way to make a bridge between R and C is : > ___________________________________ > > extern "C" { > > void foo_R(double* output, double* S, double* K){ > > > *output = foo(*S,*K,*r,*sigma,*time);Black/Scholes, eh? Dirk -- Three out of two people have difficulties with fractions.