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

Michael Braun braunm at MIT.EDU
Tue Dec 12 22:03:35 CET 2006


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 at mit.edu
(617) 253-3436



More information about the R-devel mailing list