Reputation: 1
I've written a module that includes all the necessary subroutines and functions I need. This module is a general one and I wonder if there is any way to avoid permanent use of the full-code version of the module and instead call it as a Fortran library or internal saved module?
Upvotes: 0
Views: 148
Reputation: 779
You can use the module the following way. If you build the code of a module, for this example the module is called capsule and has a subroutine called sub, the file "capsule.mod" is generated. You can now use this module in another project the following way:
Use the command
use capsule
in the subroutine, function or main program you want to use the module's subroutine.
Call the Subroutine
call sub()
And you done reusing your once build file capsule.mod.
Edit: I meant the compiler, the module have to be visible to the compiler and not to the linker.
Upvotes: 1
Reputation: 1608
Alternately, you may want to compile your generic routine as a shared library or DLL. The post Shared library in Fortran, minimal example does not work has a minimal example for gfortran and unix-y systems; an example for Intel Fortran on Windows is at https://software.intel.com/en-us/node/535308. I've seen rumors that gfortran can produce DLLs on Windows using the -shared
flag but I'd be very careful going that route.
Upvotes: 1