Skip to content

Problem with dyn.load'ed code

2 messages · Matt Calder, Hin-Tak Leung

#
Hi,
    I am having trouble with some code that I am dyn.loading. I am
writing an interface to ARPACK. I compile my interface (dssimp.cc), and
link it against the ARPACK library (libarpack_SUN4.a):

 g++ -shared -static -fPIC dssimp.cc -o dssimp.so -larpack_SUN4 -lg2c -lm 

I can dyn.load the code and it appears OK. However, when I call my
function, the call to the function in the ARPACK library returns an
error. 
	I can print the arguments to my function when I call it from R, so I
can see that I am dyn.load'd, and the arguments are passed correctly. 	
	Moreover, I can load and call the shared object (dssimp.so) using
dlopen and dlsym from a stand alone C++ program. So I can see that the
shared object is OK.
	In summary, I have a shared object that works correctly outside of R,
but when dyn.load'd into R, does not work. Short of calling errors
(which is not the case here) I wonder how that might happen, and how I
might fix it?

	Matt
#
You are missing some extern "C" declarations? R needs C linkage style.
Basically a lot of:

extern "C" {

}

around your c++ code.
Matt Calder wrote: