[Rd] Undefined symbol when trying to dyn.load a shared object

From: Michael Braun <braunm_at_MIT.EDU>
Date: Tue 12 Dec 2006 - 21:03:35 GMT


I hope that someone reading this list can offer some suggestions on how I can incorporate external C libraries in C functions that I want to call from R. I have gone through all of the documentation, help files and mailing list archives and have not been able to find a satisfactory solution.

I have constructed a simple example of the problem, since my "real" program is much more complex and would bog down discussion. Suppose I want to compute the value of a Gaussian hypergeometric function using the function in the GSL library. My C code is:

        #include </usr/include/gsl/gsl_sf_hyperg.h>

	void gslTestHG (double *a, double *b, double *c, double *x, double *val ) {
		*val = gsl_sf_hyperg_2F1(*a,*b,*c,*x); 
	}

I compile this code (successfully) using R CMD SHLIB gslTest.c and get the following result

	-bash-3.00$ R CMD SHLIB RgslTest.c
	gcc -I/usr/lib64/R/include -I/usr/lib64/R/include  -I/usr/local/include   -fpic  -O2 -g -c RgslTest.c -o RgslTest.o
	gcc -shared -L/usr/local/lib64 -o RgslTest.so RgslTest.o   -L/usr/lib64/R/lib -lR

Next, I try to load the shared object into R using dyn.load("RgslTest.so") and get the following error in R:

> dyn.load("RgslTest.so")

	Error in dyn.load(x, as.logical(local), as.logical(now)) : 
        unable to load shared library '/mnt/san2/braunm/winshare/braunm/Cpractice/RgslTest.so':
 	 /mnt/san2/braunm/winshare/braunm/Cpractice/RgslTest.so: undefined symbol: gsl_sf_hyperg_2F1

I am certain that the file path in the #include statement is correct. It looks like R can't find the gsl function in the C program, even though the compiler did.

I would greatly appreciate any help you can provide. Many thanks in advance.

Best wishes,

Michael



Michael Braun
Assistant Professor of Marketing
MIT Sloan School of Management
38 Memorial Drive, E56-329
Cambridge, MA 02139
braunm@mit.edu
(617) 253-3436

R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed Dec 13 19:49:06 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 14 Dec 2006 - 02:30:54 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.