Skip to content
Prev 38097 / 63424 Next

Linking to lapack

On Fri, 2010-10-22 at 05:30 -0400, Nick Sabbe wrote:
Yes. You need to ensure that your program is linked with a Lapack
library where the symbol dpotrf_ is defined. In an R package, using a
'Makevars' file in your 'src' directory is used to specify additional
linking. See "Writing R Extensions" section 1.2.1 Using ?Makevars?. If
you are compiling your code with a custom Makefile, then you will need
to add an argument to the linker/compiler specifying a Lapack library to
be linked. For example, here is a command that dynamically links the R
Lapack and Blas libraries to a pre-compiled 'test.o' on my system:

gcc -std=gnu99 -shared -L/usr/local/lib -o test.so test.o
-L/usr/local/lib/R/lib -lRlapack -L/usr/local/lib/R/lib -lRblas
-lgfortran -lm
It might be a good idea to build your package simultaneously with your
code, and use a Makevars file.
Three of the R manuals (R-exts, R-ints, R-admin;
http://cran.r-project.org/doc/manuals/) partially describe some aspect
of the R API, where "Writing R Extensions" is the most comprehensive.
Function descriptions are generally not biolerplate. For good or bad, a
look into the C headers is often necessary to use an R API function.

-Matt