Vla*_*ada 5 linux fortran lapack intel-mkl
我在将 lapack 链接到 fortran 示例程序时遇到问题。这是程序示例.f95
Program LinearEquations
! solving the matrix equation A*x=b using LAPACK
Implicit none
! declarations
double precision :: A(3,3), b(3)
integer :: i, pivot(3), ok
! matrix A
A(1,:)=(/3, 1, 3/)
A(2,:)=(/1, 5, 9/)
A(3,:)=(/2, 6, 5/)
! vector b
b(:)=(/-1, 3, -3/)
!b(:)=(/2, 2, 9/)
! find the solution using the LAPACK routine DGESV
call DGESV(3, 1, A, 3, pivot, b, 3, ok)
! print the solution x
do i=1, 3
  write(*,9) i, b(i)
end do  
9  format('x[', i1, ']= ', f5.2)  
end program LinearEquations
我在这里安装了库
/opt/intel/compilers_and_libraries_2017.4.196/linux/mkl/lib/intel64_lin/libmkl_lapack95_ilp64.a
我正在使用 gfortran 编译程序:
gfortran -o example example.f95 -L/opt/intel/compilers_and_libraries_2017.4.196/linux/mkl/lib/intel64_lin/libmkl_lapack95_ilp64.a
它抱怨
 /tmp/ccWtxMFP.o: In function `MAIN__':
 example.f95:(.text+0xf0): undefined reference to `dgesv_'
 collect2: error: ld returned 1 exit status
有人可以帮我解决这个问题吗?非常感谢
小智 5
有两种类型的链接:
静态链接:将程序与静态库链接。
例子:gfortran program.f90 /path-to-lib/libmy.a -o program.x 
动态链接:将程序与共享库链接:
例子 :gfortran program.f90 -L/path-to-lib -lmy -o program.x
它将您的程序与 libmy.so 链接起来。
根据MKL Advisor 的说法,你应该使用这个:
-Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_gf_lp64.a ${MKLROOT}/lib/intel64/libmkl_sequential.a ${MKLROOT}/lib/intel64/libmkl_core.a -Wl,--end-group -lpthread -lm -ldl
用于静态链接。或者 :
-L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_gf_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl
用于动态链接。
${MKLROOT}通往MKL的路在哪里?
| 归档时间: | 
 | 
| 查看次数: | 4776 次 | 
| 最近记录: |