Fortran 对LAPACK和BLAS子例程的未定义引用
我试图理解BLAS和LAPACK在Fortran中是如何工作的等等,所以我编写了一个生成矩阵并将其反转的代码 这是密码Fortran 对LAPACK和BLAS子例程的未定义引用,fortran,lapack,blas,matrix-inverse,Fortran,Lapack,Blas,Matrix Inverse,我试图理解BLAS和LAPACK在Fortran中是如何工作的等等,所以我编写了一个生成矩阵并将其反转的代码 这是密码 program test Implicit none external ZGETRF external ZGETRI integer ::M complex*16,allocatable,dimension(:,:)::A complex*16,allocatable,dimension(:)::WORK integer,allocatable,dimension(:)::
program test
Implicit none
external ZGETRF
external ZGETRI
integer ::M
complex*16,allocatable,dimension(:,:)::A
complex*16,allocatable,dimension(:)::WORK
integer,allocatable,dimension(:)::IPIV
integer i,j,info,error
Print*, 'Enter size of the matrix'
Read*, M
Print*, 'Enter file of the matrix'
READ(*,*), A
OPEN(UNIT=10,FILE = '(/A/)' ,STATUS='OLD',ACTION='READ')
allocate(A(M,M),WORK(M),IPIV(M),stat=error)
if (error.ne.0)then
print *,"error:not enough memory"
stop
end if
!definition of the test matrix A
do i=1,M
do j=1,M
if(j.eq.i)then
A(i,j)=(1,0)
else
A(i,j)=0
end if
end do
end do
call ZGETRF(M,M,A,M,IPIV,info)
if(info .eq. 0) then
write(*,*)"succeded"
else
write(*,*)"failed"
end if
call ZGETRI(M,A,M,IPIV,WORK,M,info)
if(info .eq. 0) then
write(*,*)"succeded"
else
write(*,*)"failed"
end if
deallocate(A,IPIV,WORK,stat=error)
if (error.ne.0)then
print *,"error:fail to release"
stop
end if
close (10)
end program test
矩阵A在一个文件中,我正在调用它,我还要说矩阵的大小(m)。当我用gfortran复制它们时,我得到了这些信息
/tmp/ccVkb1zY.o:在函数MAIN\uuuuu'中:
test.f03:(.text+0x751):未定义对
zgetrf_389;的引用
test.f03:(.text+0x85d):未定义对“zgetri_2;”的引用
collect2:错误:ld返回了1个退出状态
我已经安装了BLAS和LAPACK,所以我不知道我是否以正确的方式调用了库
有什么建议吗?看起来您可能没有链接到这些库。尝试:
gfortran -o test test.f03 -llapack -lblas
这会导致链接器(将所有程序部分连接在一起的程序;在UNIX上通常称为“ld”)在程序中包含LAPACK调用的库代码(或指向它的动态链接)
如果上述行的结果为“找不到-llapack”或类似,则存在两个常见问题:
gfortran -o test test.f03 -static -llapack -lblas
这也将使它寻找BLAS的静态版本;如果需要共享版本,请在“-lblas”前面添加“-shared”:
gfortran-o test test.f03-静态-llapack-共享-lblas
你可能会觉得有用看起来您可能没有链接到库。尝试:
gfortran -o test test.f03 -llapack -lblas
这会导致链接器(将所有程序部分连接在一起的程序;在UNIX上通常称为“ld”)在程序中包含LAPACK调用的库代码(或指向它的动态链接)
如果上述行的结果为“找不到-llapack”或类似,则存在两个常见问题:
gfortran -o test test.f03 -static -llapack -lblas
这也将使它寻找BLAS的静态版本;如果需要共享版本,请在“-lblas”前面添加“-shared”:
gfortran-o test test.f03-静态-llapack-共享-lblas
你可能会觉得有用你能发出编译命令吗?不,我不能。当我试图编译它的时候,我有一个错误,可能是重复的。你能给编译命令吗?不,我不能。当我试图编译它时,我有一个可能重复的错误