title: undefined reference to `gemmkernel_'--C++ routine called from Fortran
body: <p>I've been working on a Fortran routine that makes a call to a C++ method.  I'm getting the following error when I try to make it:</p>
  
  <pre><code>make -f makefile_gcc
  </code></pre>
  
  <p>Error:</p>
  
  <pre>
  gfortran -O3 -o tgemm tgemm.o mytimer.o dgemmf.o -lblas -dgemmkernel.o
  dgemmf.o: In function `dgemmf_':
  dgemmf.f:(.text+0x135): undefined reference to `gemmkernel_'
  collect2: ld returned 1 exit status
  make: *** [tgemm] Error 1
  </pre>
  
  <p>This is my makefile:</p>
  
  <pre><code>  `FC=gfortran
      CC=gcc
      FFLAGS = -O3
      CFLAGS = -O5
      BLASF=dgemmf.o
      BLASFSRC=dgemmf.f
      TIMER=mytimer.o
  
      TGEMM=tgemm
      ALL= $(TGEMM)
  
      LIBS = -lblas -dgemmkernel.o
  
      all: $(ALL)
  
      $(TGEMM): dgemmkernel.o tgemm.o $(TIMER) $(BLASF)
          $(FC) $(FFLAGS) -o $(TGEMM) tgemm.o $(TIMER) $(BLASF) $(LIBS)
  
      dgemmkernel.o: dgemmkernel.cpp  
          $(CC) $(CFLAGS) -c dgemmkernel.cpp
  
      tgemm.o: tgemm.f $(INCLUDE)
          $(FC) $(FFLAGS) -c tgemm.f
      clean:
          rm -rf *.o $(ALL) 
  </code></pre>
  
  <p>Here is my Fortran code:</p>
  
  <pre>
               SUBROUTINE DGEMMF( TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB,
           $                   BETA, C, LDC )
      *     .. Scalar Arguments ..
            CHARACTER*1        TRANSA, TRANSB
            INTEGER            M, N, K, LDA, LDB, LDC
            DOUBLE PRECISION   ALPHA, BETA
      *     .. Array Arguments ..
            DOUBLE PRECISION   A( LDA, * ), B( LDB, * ), C( LDC, * )
      *     .. External Functions ..
            LOGICAL            LSAME
            EXTERNAL           LSAME
      *     .. Local Scalars ..
            LOGICAL            NOTA, NOTB
            INTEGER            I, J, L
      *     .. Parameters ..
            DOUBLE PRECISION   ONE         , ZERO
            PARAMETER        ( ONE = 1.0D+0, ZERO = 0.0D+0 )
      *     ..
      *     .. Executable Statements ..
      *
      *     Set  NOTA  and  NOTB  as  true if  A  and  B  respectively are not transposed 
      *
            NOTA  = LSAME( TRANSA, 'N' )
            NOTB  = LSAME( TRANSB, 'N' )
      *
      *     We only want C = A°B
      *
            IF ((ALPHA.NE.ONE).OR.( BETA.NE.ZERO).OR.
           $    (.NOT.NOTA).OR.(.NOT.NOTB)) STOP
      *
      *     Start the operations.
        CALL gemmkernel( M, N, K, A, LDA, B, LDB, C, LDC)
        RETURN
  
  *     End of DGEMM.
  *
        END
  </pre>
  
  <p>And here is the C++ bit that I'm trying to call</p>
  
  <pre><code> void gemmkernel_(int * M, int * N, int * K,
                      double * a, int * LDA, 
                      double * b, int * LDB,
                      double * c, int * LDC) 
  </code></pre>
  
  <p>All of the .o files do get created, however the executable is never completed.   I suspect that the error is with my makefile because every source I've found so far suggests to me that my Fortran/C++ code is correct.  </p>