(If the project does not compile a LIB file, try putting a module-less subroutine that calls a library routine. The easiest way to run DUMPBIN is to open the Visual Studio command prompt from the Start Menu (or a shortcut) and cd to the target directory. DUMPBIN is a command line utility for inspecting binaries. This is important when using LIB files from 3rd parties. This will affect how the compiler exports the name of the function in the LIB.įunction Subtract(x, y) result(z) bind(c)Īfter you compile the LIB file, you can use DUMPBIN to inspect how the functions are being exposed. The Subtract subroutine has the bind(c) attribute. The static library has a single module with some advanced numerical computation routines. The solution has two projects: the “Calculator” static library and the main console application that calls the Calculator.
The the example below shows how to compile a static libraries into a Fortran console application. Organization Splitting up a large project into several static libraries makes the application easier to understand and maintain.This use case is not covered in this post. This use case is more complicated since certain compiler options can cause binary incompatibilities such as the choice run-time library.
When developing a Fortran function for use with IMLPlus, bear in mind the following: To the documentation for your Fortran package. If you are using development tools other than Compaq Visual Fortran, you may need to use different compiler directives. Specifies that the function uses the C calling convention. In the example above, the compiler directiveĮxports the function from the DLL and the directive
Upon successful compilation and linking, the file My_Fortran_Functions.dll should exist in the project's Debug directory. !DEC$ ATTRIBUTES C :: My_Fortran_Function !DEC$ ATTRIBUTES DLLEXPORT :: My_Fortran_Function Integer(4) function My_Fortran_Function( n, c, x, y ) result ( rc ) ! Return 0 if the computation succeeds, otherwise return 1 ! Create a function that computes y = c*x for vector x and scalar c In the Functions.f90 file, type the following source code:.(The older Fixed Format style was identified as obsolescent in Fortran 95.)
In the list, select Fortran Free Format Source File.On the Project menu, click Add To Project, and then click New.Visual Fortran will display the New Project Information dialog box. Select the option An empty DLL application.Visual Fortran will display the wizard for creating a Win32 Dynamic-Link Library project. In the Project name box, type My_Fortran_Functions.In the list, select Fortran Dynamic-Link Library.Visual Fortran will display the New dialog box. To create a DLL that exports a Fortran function Since this example was written, Compaq Visual Fortran has been
The example shown here assumes the use of Compaq Visual Fortran Professional Edition Version 6.5. The steps required to accomplish this task are highly dependent on the softwareĭevelopment tools used. Packaging a Fortran Function within a DLL Packaging a Fortran Function within a DLLīefore you can call a Fortran function from an IMLPlus program, you must first package the function within a DLL.