centOS安装blas、lapack

本文详细介绍了LAPACK3.11的安装步骤,包括下载、编译、库文件的复制和环境变量配置。在安装完成后,提到了一种可能出现的链接错误,该错误涉及gfortran的相关函数,并给出了解决方案,即调整静态库的链接顺序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

安装包地址

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!

环境变量配置

  1. 确认~/lapack-3.11以下静态库文件已正确生成:
    librefblas.a、libcblas.a、liblapack.a、liblapacke.a

  2. 头文件在以下位置:
    cblas头文件路径: ~/lapack-3.11/CBLAS/include
    lapacke头文件路径: ~/lapack-3.11/LAPACKE/include

  3. 非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
  1. 编写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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值