- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I've got an error while compiling this short program using "interface" :
[fortran]
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
[/fortran]
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page