Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Fortran DLL for Mixed Programming Interface

Status
Not open for further replies.

vdubbin

Technical User
Sep 9, 2009
2
US
Hello All,

I know this is not really a new topic - but I'm new to Fortran and lost in the bits and pieces I've found regarding the creation of a DLL usable from another program (for example LabVIEW, Visual Basic, C, etc).

For myself, I plan to use LabVIEW to call some existing Fortran code that does some really neat Mie Scattering calculations.

LabVIEW can use C or STDCALL conventions.
I’m use the newest version of gfortran as my compiler

To explore how to do this I wrote a simple program:

Example.f
subroutine Sub1 (A,B,C)
implicit none
Real*8 A,B,C
call Sub2 (A,B,C)
print*,C
end

subroutine Sub2 (A2,B2,C2)
implicit none
Real*8 A2,B2,C2
C2=A2+B2
end


I only really need to make “Sub1” available to the outside world. I believe there are two things I need to get right for everyone to be happy - define calling convention and limit name-mangling – for example:

1)Put somewhere in my program (and correctly use)
a) !GCC$ ATTRIBUTES attribute-list :: variable-list (including STDCALL)
b) DLLEXPORT (if needed)
2)Specify the correct command line options for gfortran compilation
e.g. gfortran –shared –o example.dll example.f

For whatever reason I’m not having much luck finding documentation that clearly states how to use these commands/modifiers…ho hum….

Anyway, all help is very much appreciated!
Cheers,
-Jeff
 
Hello All,

I am either luck or its not really that hard - I have my code working (for now)!

I simply left the code as-is (without adding DLLEXPORT or !GCC$ attribute).

I compliled using:
gfortran -shared -o example.dll example.f

***I found that while gfortran would compile and run an .exe (a.exe) for my code through windows command prompt, the DLL would only be valid if created through the unix shell I'm using, cygwin**

I still don't know where I would have found the documentation for the -shared -o...

I'm using LabVIEW and simply call the dll, matched variable data type, used STDCALL convention, and pass "pointer to value".

All seems well.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top