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

Calling Fortran subroutine in Fortran DLL from Fortran Main program

avinash_roshan
Beginner
766 Views

Hello;

I am new to fortan. I am using Intel fortran81.

I want to know how I can call fortran subroutine defined in a fortran dll file from a main program written in fortran.

Could you provide me a sampleof both(fortran dll and fortran main program).

Thankx in advance.

Regards

Avinash

0 Kudos
2 Replies
Steven_L_Intel1
Employee
766 Views
I am curious as to why you're using such an old version of the compiler.

There's nothing special you need to do to call a routine provided in a DLL other than link with the DLL's export library. If you have a Fortran executable calling a Fortran DLL, you should build the executable with the /libs:dll option otherwise you might have trouble using I/O or allocatable variables.

Here's a simple sample:

dllsub.f90

subroutine dllsub
!dec$ attributes dllexport :: dllsub
print *, "Hello from dllsub!"
end subroutine dllsub

main.f90

program main
call dllsub
end program main

Build commands:

ifort /dll dllsub.f90
ifort /libs:dll main.f90 dllsub.lib

You can optionally add:

!dec$ attributes dllimport :: dllsub

to the source for main.f90, but it is not required for routines. (It is for imported variables.)
0 Kudos
avinash_roshan
Beginner
766 Views

Dear Steve;

Thankyou very much for your help.

I am working with a tool called Abaqus. The version I use of this tool requires Intel Compiler 8x.That's why I have to use the old compiler.

Regards

Avinash

0 Kudos
Reply