Hi, I am working on a UNIX machine and I am interfacing R and C with the .C function. I am trying to call LAPACK and BLAS routines, but am running into a problem where, while I am able to run the BLAS routines, I cannot run the LAPACK routines. I compile my .c file (at end of email) in the following way: [mhitczen at jlogin2 ~/Cstuff]$ R CMD SHLIB testmore.c gcc -std=gnu99 -I/home/mhitczen/R-2.9.0/include -I/usr/local/include -fpic -g -O2 -c testmore.c -o testmore.o gcc -std=gnu99 -shared -L/usr/local/lib -o testmore.so testmore.o However, I get the following error in R:> dyn.load("testmore.so")Error in dyn.load("testmore.so") : unable to load shared library '/home/mhitczen/Cstuff/testmore.so': /home/mhitczen/Cstuff/testmore.so: undefined symbol: dpotrf_ This error goes away and everything works when I simply call the BLAS routine (In the testmore.c file I simply remove funct2, leaving funct which calls the routine "dgemm" found in the BLAS.h file). I read the "Writing R Extensions" and created a file: /R-2.9.0/src/Makevars that contains the line: PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) What am I doing wrong? Thanks for your time and effort. My testmore.c file is: #include <Rinternals.h> #include <Rmath.h> #include <R.h> #include <R_ext/Applic.h> #include <R_ext/Lapack.h> #include <R_ext/BLAS.h> #include <R_ext/RS.h> // FUNCTION CALLING BLAS void funct(double *x, int *dim, double *y, double *result){ double one=1.0; double zero =0.0; char *transa="N"; char *transb="N"; F77_CALL(dgemm) (transa,transb,dim,dim,dim,&one,x,dim,y,dim,&zero,result,dim); } // FUNCTION CALLING LAPACK void funct4(double *x, int *dim, double *result){ char *UorL="L"; int info=0; F77_CALL(dpotrf)(UorL,dim,x,dim, &info); } Best, Marcin Hitczenko
On Fri, 4 Sep 2009, Marcin Hitczenko wrote:> Hi, > > I am working on a UNIX machine and I am interfacing R and C with the .C > function. I am trying to call LAPACK and BLAS routines, but am running > into a problem where, while I am able to run the BLAS routines, I cannot > run the LAPACK routines. > > I compile my .c file (at end of email) in the following way: > > [mhitczen at jlogin2 ~/Cstuff]$ R CMD SHLIB testmore.c > > gcc -std=gnu99 -I/home/mhitczen/R-2.9.0/include -I/usr/local/include > -fpic -g -O2 -c testmore.c -o testmore.o > gcc -std=gnu99 -shared -L/usr/local/lib -o testmore.so testmore.o > > However, I get the following error in R: > >> dyn.load("testmore.so") > Error in dyn.load("testmore.so") : > unable to load shared library '/home/mhitczen/Cstuff/testmore.so': > /home/mhitczen/Cstuff/testmore.so: undefined symbol: dpotrf_ > > This error goes away and everything works when I simply call the BLAS > routine (In the testmore.c file I simply remove funct2, leaving funct > which calls the routine "dgemm" found in the BLAS.h file). > > I read the "Writing R Extensions" and created a file: > /R-2.9.0/src/Makevars that contains the line: > PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)That is not where it tells you to put the file. It needs to be in the direcctory where you run the compile (normally the 'src' directory of a package), and in your case that seems to be ~/Cstuff. That BLAS works is fortuitous, depending on the way you built R. [...] -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Maybe Matching Threads
- Problem with shared library and lapack under windows
- When calling external C-function repeatedly I get different results; can't figure out why..
- When calling external C-function repeatedly I get differentresults; can't figure out why..
- Using matprod from array.c
- question about dll crashing R