title: undefined reference to `dgemm_' in gfortran in windows subsystem ubuntu
body: <p>I have the following Fortran code from <a href="https://software.intel.com/content/www/us/en/develop/documentation/mkl-tutorial-fortran/top/multiplying-matrices-using-dgemm.html" rel="nofollow noreferrer">https://software.intel.com/content/www/us/en/develop/documentation/mkl-tutorial-fortran/top/multiplying-matrices-using-dgemm.html</a></p>
  <p>I am trying to use gfortran complile it (named as <code>dgemm.f90</code>)</p>
  <pre><code>! Fortran source code is found in dgemm_example.f
  
        PROGRAM   MAIN
  
        IMPLICIT NONE
  
        DOUBLE PRECISION ALPHA, BETA
        INTEGER          M, K, N, I, J
        PARAMETER        (M=2000, K=200, N=1000)
        DOUBLE PRECISION A(M,K), B(K,N), C(M,N)
  
        PRINT *, &quot;This example computes real matrix C=alpha*A*B+beta*C&quot;
        PRINT *, &quot;using Intel(R) MKL function dgemm, where A, B, and C&quot;
        PRINT *, &quot;are matrices and alpha and beta are double precision &quot;
        PRINT *, &quot;scalars&quot;
        PRINT *, &quot;&quot;
  
        PRINT *, &quot;Initializing data for matrix multiplication C=A*B for &quot;
        PRINT 10, &quot; matrix A(&quot;,M,&quot; x&quot;,K, &quot;) and matrix B(&quot;, K,&quot; x&quot;, N, &quot;)&quot;
  10    FORMAT(a,I5,a,I5,a,I5,a,I5,a)
        PRINT *, &quot;&quot;
        ALPHA = 1.0 
        BETA = 0.0
  
        PRINT *, &quot;Intializing matrix data&quot;
        PRINT *, &quot;&quot;
        DO I = 1, M
          DO J = 1, K
            A(I,J) = (I-1) * K + J
          END DO
        END DO
  
        DO I = 1, K
          DO J = 1, N
            B(I,J) = -((I-1) * N + J)
          END DO
        END DO
  
        DO I = 1, M
          DO J = 1, N
            C(I,J) = 0.0
          END DO
        END DO
  
        PRINT *, &quot;Computing matrix product using Intel(R) MKL DGEMM &quot;
        PRINT *, &quot;subroutine&quot;
        CALL DGEMM('N','N',M,N,K,ALPHA,A,M,B,K,BETA,C,M)
        PRINT *, &quot;Computations completed.&quot;
        PRINT *, &quot;&quot;
  
        PRINT *, &quot;Top left corner of matrix A:&quot;
        PRINT 20, ((A(I,J), J = 1,MIN(K,6)), I = 1,MIN(M,6))
        PRINT *, &quot;&quot;
  
        PRINT *, &quot;Top left corner of matrix B:&quot;
        PRINT 20, ((B(I,J),J = 1,MIN(N,6)), I = 1,MIN(K,6))
        PRINT *, &quot;&quot;
  
   20   FORMAT(6(F12.0,1x))
  
        PRINT *, &quot;Top left corner of matrix C:&quot;
        PRINT 30, ((C(I,J), J = 1,MIN(N,6)), I = 1,MIN(M,6))
        PRINT *, &quot;&quot;
  
   30   FORMAT(6(ES12.4,1x))
  
        PRINT *, &quot;Example completed.&quot;
        STOP 
  
        END
  
  </code></pre>
  <p>By <code>gfortran  -lblas -llapack dgemm.f90</code>,  I got</p>
  <pre><code>/tmp/ccUtHQz1.o: In function `MAIN__':
  dgemm.f90:(.text+0x794): undefined reference to `dgemm_'
  collect2: error: ld returned 1 exit status
  </code></pre>
  <p>I searched that this type of question has been asked time to time, but I haven't found a solution for my case :(</p>
  <p>I tried to use python load blas, based on <a href="https://software.intel.com/content/www/us/en/develop/articles/using-intel-mkl-in-your-python-programs.html" rel="nofollow noreferrer">https://software.intel.com/content/www/us/en/develop/articles/using-intel-mkl-in-your-python-programs.html</a></p>
  <pre><code>from ctypes import *
  
  mkl = cdll.LoadLibrary(&quot;./anaconda3/lib/libmkl_rt.so&quot;)
  dgemm = mkl.cblas_dgemm
  
  def print_mat(mat, m, n):
    for i in xrange(0,m):
      print &quot; &quot;,
      for j in xrange(0,n):
        print mat[i*n+j],
      print 
  
  Order = 101  # 101 for row-major, 102 for column major data structures
  TransA = 111 # 111 for no transpose, 112 for transpose, and 113 for conjugate transpose
  TransB = 111
  m = 2
  n = 4
  k = 3
  lda = k
  ldb = n
  ldc = n
  alpha = 1.0
  beta = -1.0
  
  amat = c_double * 6
  bmat = c_double * 12
  cmat = c_double * 8
  a = amat(1,2,3, 4,5,6)
  b = bmat(0,1,0,1, 1,0,0,1, 1,0,1,0)
  c = cmat(5,1,3,3, 11,4,6,9)
  
  
  
  print &quot;\nMatrix A =&quot;
  print_mat(a,2,3) 
  print &quot;\nMatrix B =&quot;
  print_mat(b,3,4)
  print &quot;\nMatrix C =&quot;
  print_mat(c,2,4)
  
  print &quot;\nCompute&quot;, alpha, &quot;* A * B + &quot;, beta, &quot;* C&quot;
  
  dgemm( c_int(Order), c_int(TransA), c_int(TransB), c_int(m), c_int(n), c_int(k), c_double(alpha), byref(a), c_int(lda), byref(b), c_int(ldb), c_double(beta), byref(c), c_int(ldc))
  
  print_mat(c,2,4)
  print
  </code></pre>
  <p>The above code works. Hence, the question may be related to use mkl with gfortran?</p>