[R] Question about building library and BLAS

Douglas Bates bates at stat.wisc.edu
Mon May 31 18:29:19 CEST 2004


Zhu Wang <zhuw at mail.smu.edu> writes:

> I am trying to create a library which uses some Fortran source files

  Someone named Martin Maechler will shortly be sending you email
  regarding the distinction between 'library' and 'package' :-)

  (You are creating a package, not a library, despite the fact that
   you will later attach it using a function called 'library'.)

> and Lapack and Blas subroutines. The Fortran source files from the
> original author contain subroutines isamax.f, sgefa.f and sgesl.f,
> which are part of BLAS subroutines on my Linux computer, but maybe
> different (old) versions. So in addition to these subroutines, there
> are other Lapack and Blas subroutines involved. There is no problem
> to compile and run these files using g77, such as the following to
> create car:
> 
> g77 -mieee-fp  -fPIC  -O2 -g -pipe -march=i386 -mcpu=i686 car
> isamax.f, sgefa.f sgesl.f foo1.f ... foo20.f -llapack -lblas
> 
> By doing this, the procedure does not use subroutines isamax.f, sgefa.f sgesl.f in BLAS,
> as expected. In fact, there are problems to use these subroutines in BLAS, for some reason.
> 
> Now what I want is to build an R library. The Makefile is the following:
> 
> LIBNAME=car
>  
> PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
>  
> OBJS=isamax.o saxpy.o sscal.o foo1.o ... foo20.o -llapack -lblas
> 
> $(LIBNAME)$(SHLIB_EXT): $(OBJS)
>         $(SHLIB_LD) $(SHLIB_LDFLAGS) -o $@ $(OBJS) $(FLIBS)
>  
> clean:
>         @rm -f *.o *.$(SHLIB_EXT)
>  
> realclean: clean
> 
> Some compiling outputs are the following:
> 
> g77 -mieee-fp  -fPIC  -O2 -g -pipe -march=i386 -mcpu=i686 -c isamax.f
> -o isamax.o
> ...
> g77 -mieee-fp  -fPIC  -O2 -g -pipe -march=i386 -mcpu=i686 -c foo1.f -o
> foo1.o
> ......
> gcc -shared -o car.so isamax.o ...... foo20.o -llapack -lblas
> -L/usr/local/lib -L/usr/lib/gcc-lib/i386-redhat-linux/3.3.2
> -L/usr/lib/gcc-lib/i386-redhat-linux/3.3.2/../../.. -lfrtbegin -lg2c
> -lm -lgcc_s
> 
> However, it turns out that this process did not take into account these 
> three files isamax, sgefa.f and sgesl.f. 
> Instead, it used subroutines in Blas, but again for some reason, it provided
> error. 

I think you are working too hard.  Temporarily move the source files
for the BLAS and Lapack routines to backup names, such as
isamax.f.old, then do the same to the Makefile (i.e. move it to
Makefile.old) then create a file called Makevars containing

PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)




More information about the R-help mailing list