Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29245 Discussions

Can I call "C" util from Fortran "Module" DLL subroutines

fbalderasintel
575 Views

I have no problem calling C from Fortran Program. But I cant seem to set up an interface from within a Fortran "Module" DLL.I belive the interface should be inside the subroutine, but no, so place outside, sevaral places. No Joy.

This is a compile time issue.Many compile errors. Is this not "Doable" ? IVF11.1.046/Vista/x64
Here is with interface declared inside subroutine calling on CPP (C++)routine.
Here is the module:

module K3_FortranDLL

contains

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

subroutine CreateConnection()

!DEC$ ATTRIBUTES DLLEXPORT :: CreateConnection

interface

subroutine CreateConnectionCPP (string) bind(C,"CreateConnectionCPP")

implicit none

character, dimension(*) :: string

end subroutine CreateConnectionCPP

end interface

character(100) string

integer i

! As an example, write the integers 1 to 10 in a loop

do i=1,10

! Convert the number to a string and add a trailing newline (\\n) plus a NUL termination

write (string,'(I0,A)') i,C_NEW_LINE//C_NULL_CHAR

! Call C++ to write the text

! Note that Fortran allows a character string to be passed to an

! array of single characters. The NUL is needed because no length is passed.

call cout_sub (string)

end do

end subroutine

end module K3_FortranDLL

0 Kudos
1 Solution
mecej4
Honored Contributor III
575 Views
Add
[fortran]use iso_c_binding[/fortran]
after the SUBROUTINE declaration statement. In the Interface, the accepted syntax is
[bash]subroutine CreateConnectionCPP (string) bind(C,name='CreateConnectionCPP')[/bash]
With these changes, the module can be compiled with no error messages.

View solution in original post

0 Kudos
1 Reply
mecej4
Honored Contributor III
576 Views
Add
[fortran]use iso_c_binding[/fortran]
after the SUBROUTINE declaration statement. In the Interface, the accepted syntax is
[bash]subroutine CreateConnectionCPP (string) bind(C,name='CreateConnectionCPP')[/bash]
With these changes, the module can be compiled with no error messages.
0 Kudos
Reply