前言
略
安装包地址
https://www.netlib.org/lapack/
安装过程
tar -zvx -f lapack-3.11.tar.gz
cd ~/lapack-3.11
cp make.inc.example make.inc
make blaslib
make cblaslib
make lapacklib
make lapackelib
没有报错,OK!
环境变量配置
-
确认~/lapack-3.11以下静态库文件已正确生成:
librefblas.a、libcblas.a、liblapack.a、liblapacke.a -
头文件在以下位置:
cblas头文件路径: ~/lapack-3.11/CBLAS/include
lapacke头文件路径: ~/lapack-3.11/LAPACKE/include -
非root用户,在home下创建opt/lapack/3.11,将以上静态库和头文件复制至此,建立子目录include存放头文件,建立子目录lib存放*.a文件:
cp -r lib* LAPACKE/include/ CBLAS/include/ ~/opt/lapack/3.11/
mkdir lib
mv lib*.a lib
- 编写module file 文件
#%Module1.0
## Module file created by xxx@mail.com
proc ModulesHelp { } {
puts stderr "lapack-3.11, by gcc/gfortran"
}
set LAPACK /home/xxx/opt/lapack/3.11
prepend-path LD_LIBRARY_PATH ${LAPACK}/lib
prepend-path LIBRARY_PATH ${LAPACK}/lib
prepend-path INCLUDE_PATH ${LAPACK}/include
prepend-path CPATH ${LAPACK}/include
prepend-path FPATH ${LAPACK}/include
注意事项
若使用lapack过程中出现如下错误,
/es01/home/gaobfjn95/opt/lapack/3.11/lib/liblapack.a(dtrtri.o): In function `dtrtri_':
dtrtri.f:(.text+0x13d): undefined reference to `_gfortran_concat_string'
/es01/home/gaobfjn95/opt/lapack/3.11/lib/liblapack.a(ilaenv.o): In function `ilaenv_':
ilaenv.f:(.text+0x59): undefined reference to `_gfortran_compare_string'
ilaenv.f:(.text+0x276): undefined reference to `_gfortran_compare_string'
ilaenv.f:(.text+0x29f): undefined reference to `_gfortran_compare_string'
ilaenv.f:(.text+0x2d9): undefined reference to `_gfortran_compare_string'
ilaenv.f:(.text+0x2fa): undefined reference to `_gfortran_compare_string'
/es01/home/gaobfjn95/opt/lapack/3.11/lib/liblapack.a(ilaenv.o):ilaenv.f:(.text+0x319): more undefined references to `_gfortran_compare_string' follow
/es01/home/gaobfjn95/opt/lapack/3.11/lib/liblapack.a(xerbla.o): In function `xerbla_':
xerbla.f:(.text+0x49): undefined reference to `_gfortran_st_write'
xerbla.f:(.text+0x54): undefined reference to `_gfortran_string_len_trim'
xerbla.f:(.text+0x66): undefined reference to `_gfortran_transfer_character_write'
xerbla.f:(.text+0x76): undefined reference to `_gfortran_transfer_integer_write'
xerbla.f:(.text+0x7e): undefined reference to `_gfortran_st_write_done'
xerbla.f:(.text+0x87): undefined reference to `_gfortran_stop_string'
/es01/home/gaobfjn95/opt/lapack/3.11/lib/liblapack.a(iparmq.o): In function `iparmq_':
iparmq.f:(.text+0x1c9): undefined reference to `_gfortran_compare_string'
iparmq.f:(.text+0x1e4): undefined reference to `_gfortran_compare_string'
iparmq.f:(.text+0x200): undefined reference to `_gfortran_compare_string'
iparmq.f:(.text+0x265): undefined reference to `_gfortran_compare_string'
iparmq.f:(.text+0x280): undefined reference to `_gfortran_compare_string'
可能是由静态库的链接顺序不对导致,建议按如下顺序链接静态库
gcc test.c -o test -llapacke -llapack -lcblas -lrefblas -lm -lgfortran
参考链接:
https://zhuanlan.zhihu.com/p/520848641