Ifort 12 / Undefined reference while compiling interface

Ifort 12 / Undefined reference while compiling interface

Rémi B.'s picture

Hi,

I've got an error while compiling this short program using "interface" :

      subroutine TEST (*)
      
      use, intrinsic :: iso_c_binding
      implicit none
      
      ! ===== Variables =====
      
      logical, save :: MAKE_INIT = .TRUE.
      logical           BRET
      
      ! ===== Solver interface =====
      interface
         logical function Init( theDataDir, theWriteStep ) BIND(C, NAME=
     1'Init')
         IMPORT C_INT
         character, DIMENSION(*) :: theDataDir
         integer(C_INT) :: theWriteStep
         end function Init
      end interface
      
      if ( MAKE_INIT ) then
         write (*,*) 'Init solver...'
         BRET = INIT( '/u1/home/'//char(0), 100_C_INT )
         if ( BRET .EQV. .FALSE. ) then
            write (*,*) 'Init solver: ERROR '
            stop
         end if
         write (*,*) 'Init solver: OK'
         MAKE_INIT = .FALSE.
       end if
      RETURN 
      END

I'm using ifort version 12.1.5 with the following compiling line : 

     ifort TEST.f

I've got the following error message :

TEST.f:(.text+0xc8): undefined reference to `Init'

LD_LIBRARY_PATH points at the correct location. Am I missing something or is it a problem of IFC installation or options ?

Thanks for your help.

 

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
HeinzB (Intel)'s picture

Hello Remi

you only defined an INTERFACE to the C-function Init() but I don't see, that you add the object code of Init() to your link step. You need to add this code. E.g. assuming that your routine Init() is defined in a source file my_init.c being compiled to my_init.o, you need to run "ifort TEST.f my_init.o"

Heinz

Rémi B.'s picture

Thanks for the answer. I add to the compiling line a link to a librairy which defines the Init routine and it works. Subject can be close.

Login to leave a comment.