Linking LAPACK from Intel MKL with gfortran

Viewed 4045

I have a problem to link lapack to fortran example program. Here is the program example.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

I have installed libraries here

/opt/intel/compilers_and_libraries_2017.4.196/linux/mkl/lib/intel64_lin/libmkl_lapack95_ilp64.a

I am using gfortran to compile program:

gfortran -o example example.f95 -L/opt/intel/compilers_and_libraries_2017.4.196/linux/mkl/lib/intel64_lin/libmkl_lapack95_ilp64.a

it complain

 /tmp/ccWtxMFP.o: In function `MAIN__':
 example.f95:(.text+0xf0): undefined reference to `dgesv_'
 collect2: error: ld returned 1 exit status

Can someone help me with this issue please ? Many thanks

2 Answers
Related