[Rd] libRblas.so: undefined reference to `xerbla_' ?

Andre Zege azege at yahoo.com
Sat Jan 22 03:43:58 CET 2011

Hi all, i am trying to compile a test, calling from C code  R Lapack  shared 
libraries. In particular, i am calling simple LAPACK driver 

dposv for solving linear equation  system A*x=B  with positive definite A. My 
code looks like the following in 

#include <R_ext/BLAS.h> 
#include <R_ext/Lapack.h> 

int main(){ 
  double A[4]={1,0.5,0.5,1}; 
  double B[2]={3,4}; 
  char uplo='U'; 
  int n = 2, nrhs=1, lda=2, ldb=2, info, i; 
  F77_CALL(dposv)(&uplo,&n, &nrhs, A, &lda, B, &ldb, &info); 
  for(i=0; i<2; i++){ 
    printf("%f\n", B[i]); 
  return info; 

When I am trying to link to BLAS/LAPACK using 

gcc -std=gnu99 solve.c -o test -I$R_HOME/include -L$R_HOME/lib -lRblas -lRlapack 

linker generates an error message 
$RHOME/lib/libRblas.so: undefined reference to `xerbla_' 

Dumping symbol table shows that indeed libRblas.so has undefined  xerbla_ symbol 
and so does libRlapack. Confusingly, documentation says  that xerbla is error 
checking routine for BLAS, but it is not found in  the library libRblas. 

I did find out that xerbla is defined in libR.so and when i link  to R library, 
everything seems to go fine. However, i have a nagging  feeling i am doing 
something wrong. It doesn't make sense to me that i  cannot compile code that 
doesn't use R without linking to R. Also, one  would want to switch 
transparently between different implementations of  BLAS for example for testing 
purposes and not modify linking  instructions. Would appreciate if someone with 
better understanding of R  commented on how to properly link to  BLAS and LAPACK 
libraries  included with R.

More information about the R-devel mailing list