Dear helpers, I am trying to create a library which uses some Fortran source files 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. My question is how do I set up my Makefile, or maybe other files, such that I have the same result as I did to compile and run these Fortran files directly. Thanks in advance. -- Zhu Wang Statistical Science Department Southern Methodist University Dallas, TX 75275-0332 Phone:(214)768-2453 Fax:(214)768-4035 zhuw at mail.smu.edu
Zhu Wang <zhuw at mail.smu.edu> writes:> I am trying to create a library which uses some Fortran source filesSomeone 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)