编译lapack动态链接库

(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:
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

 

转自http://pduwork.pbworks.com/w/page/8509998/lapack-as-a-shared-library,有修改,原文的错误已修正。
此条目发表在HPC分类目录,贴了, , , 标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。

验证图片

*