| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

lapack as a shared library

Page history last edited by Peng Du 11 years, 5 months ago

This following applies to lapack3.1.1.

 

(1) Adding -fPIC to

     OPTS & NOOPT in make.inc

 

(2) Change the names in make.inc

BLASLIB      = ../../blas$(PLAT).so

LAPACKLIB    = ../lapack$(PLAT).so

TMGLIB       = tmglib$(PLAT).so

 

(3) In ./SRC, change the Makefile from

 

../$(LAPACKLIB): $(ALLOBJ)

   $(ARCH) $(ARCHFLAGS) $@ $(ALLOBJ)

   $(RANLIB) $@

 

to

 

../$(LAPACKLIB): $(ALLOBJ)

    $(LOADER) $(LOADOPTS) -shared -Wl,-soname,liblapack.so -o $@ $(ALLOBJ)

 

And no, I also don't know why "-Wl,-soname,liblapack.so" is necessary. Can someone shed a little light here?

 

(4) In ./BLAS/SRC, change the Makefile from

 

$(BLASLIB): $(ALLOBJ)

   $(ARCH) $(ARCHFLAGS) $@ $(ALLOBJ)

   $(RANLIB) $@

 

to

$(BLASLIB): $(ALLOBJ)

    $(LOADER) $(LOADOPTS) -z muldefs -shared -Wl,-soname,libblas.so -o $@ $(ALLOBJ)

 

And "-z muldefs" is used to handle multiple definitions in $(ALLOBJ)...whew~! [see [2]]

 

(5) In ./TESTING/MATGEN, change the Makefile from

 

../../$(TMGLIB): $(SMATGEN) $(CMATGEN) $(SCATGEN) $(DMATGEN)   \

       $(ZMATGEN) $(DZATGEN)

   $(ARCH) $(ARCHFLAGS) $@ $(ALLOBJ)

   $(RANLIB) $@

 

to

../../$(TMGLIB): $(ALLOBJ)

    $(LOADER) $(LOADOPTS) -shared -Wl,-soname,libtmglib.so -o $@ $(ALLOBJ)

 

(6) create a bunch of soft links:

 

ln -sf tmglib_LINUX.so libtmglib.so

ln -sf lapack_LINUX.so liblapack.so

ln -sf blas_LINUX.so libblas.so

 

Add these to ./Makefile

lib: blaslib lapacklib tmglib

    ln -sf tmglib_LINUX.so libtmglib.so

    ln -sf lapack_LINUX.so liblapack.so

    ln -sf blas_LINUX.so libblas.so

 

which used to be just

lib: blaslib lapacklib tmglib

 

Note that for sure you could do it without having to do these softlinks, for example when create the refblas, instead of doing

$(LOADER) $(LOADOPTS) -z muldefs -shared -Wl,-soname,libblas.so -o $@ $(ALLOBJ)

 

you could do

$(LOADER) $(LOADOPTS) -z muldefs -shared -Wl,-soname,blas_LINUX.so -o $@ $(ALLOBJ)

 

But the softlink give a good view of how shared library is only loaded when executing a program that requires them, eg:

 

with the softlink liblapack.so, you'll get this:

du:/home/du/lib/tmp/lapack-3.1.1/TESTING@grig-compile ~> ./xlintstc

./xlintstc: error while loading shared libraries: liblapack.so: cannot open shared object file: No such file or directory

 

And without setting LD_LIBRARY_PATH, you might get:

du:/home/du/lib/tmp/lapack-3.1.1/TESTING@grig-compile ~> ./xlintstc

./xlintstc: error while loading shared libraries: libtmglib.so: cannot open shared object file: No such file or directory

 

(7) TO USE

 

     i. Compile and create libblas.so, liblapack.so and libtmglib.so by typing make in the lapack directory

     ii.  Add the path of the three .so files to LD_LIBRARY_PATH, eg:

          export LD_LIBRARY_PATH=/home/du/lib/lapack-3.1.1.shared_lib:LD_LIBRARY_PATH

     iii. link with your own program using -llapack -lblas and maybe -ltmglib

 

 

 

 

 

Reference:

[1] http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html

[2] http://sources.redhat.com/binutils/docs-2.16/ld/Options.html

Comments (0)

You don't have permission to comment on this page.