Farid
Farid

Reputation: 1

Is it possible to save the module as a library to avoid its permanent copy and past in each program code

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

Answers (2)

Alex
Alex

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:

  1. Add capsule.mod to the list of files the linker should use, or if you use an ide, simply copy the file into the folder, where all the objectcode files are.
  2. Use the command

    use capsule
    

    in the subroutine, function or main program you want to use the module's subroutine.

  3. 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

arclight
arclight

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

Related Questions