Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8012905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:28:47+00:00 2026-06-04T19:28:47+00:00

I’m using gfortran’s 95+ extensions. I have a library of utility modules I’d like

  • 0

I’m using gfortran’s 95+ extensions. I have a library of utility modules I’d like to link to other projects, i.e. as a library or shared object / dll. However, in Fortran, I don’t understand how to split the interface from the implementation in Fortran without maintaining two copies of the module interface.

In C, I would separate the interface from the implementation like:

 api.h ←includes← impl.h
   ↑                 ↑
includes          includes
   ↑                 ↑
 user.c           impl.c

Is there a way to achieve the same effects in modern Fortran? Do I need to provide users my library with the .mod files?

  • Single definition of an explicit interface
  • Only interface definitions are exposed to the user code

Edit: To sum up (what I think is) the answer:

  • .mod files are needed, as they contain the explicit interface definition

  • There is no standard Fortran ABI for modules — .mod files will be compiler-specific

  • The only directly analgous approach to the implementation-hiding problem is submodules, which are defined in Fortran 2008, and which gfortran does not support.

  • The most practical approach, aside from avoiding modules, noted by @High-Performance-Mark and the Fedora page, is to distribute include files for interface-only modules along with precompiled .mods for the implementation.

  • Using includes has some well-known and annoying trip-ups, including the potential redefinition of common blocks.

I am a little surprised there is not actually a straightforward answer here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:28:50+00:00Added an answer on June 4, 2026 at 7:28 pm

    I believe that you can do this with submodules using Fortran 2008 compilers. From FortranWiki:

    Submodules are a feature of Fortran 2008 which allow a module procedure to have its interface defined in a module while having the body of the procedure defined in a separate unit, a submodule.

    From Wikipedia (emphasis mine)

    [Submodules allow] the specification and implementation of a module to be expressed in separate program units, which improves packaging of large libraries, allows preservation of trade secrets while publishing definitive interfaces, and prevents compilation cascades.

    I don’t have any experience with submodules, and they are not widely supported yet, but they are something to be aware of.

    Edit Since many compilers don’t support submodules, it is probably helpful to discuss other options.

    This page asks a similar question to this and has a number of nice links. Particularly useful in a discussion on Google Groups (see, in particular, this post). In summary, one option is to:

    • Group all the library functions/subroutines in a single file and by themselves (i.e. not being part of a module).

    • Create a module that only contains interfaces for those subroutines that you want to expose to the end user.

    • Provide end-users with the compiled module and the library. The user can then use the module in his/her programs and link against the library.

    This allows you to "hide" functions/subroutines that you don’t want to expose to the end user.

    Lifted from the post I link to:

    Some compilers generate a .mod (or whatever name the compiler gives to it) file and a library file. The .mod file has the symbols; the library file contains the executable code included in the module. When this is the case, you must distribute both files to your end users.

    Also, some compilers (in particular f95) put the symbols and the executable code into a single .mod file. In this case, you only need to provide the .mod file to your end users.

    (final!) edit There is a useful page on the Fedora wiki:

    Ideally, portable Fortran libraries would avoid the use of modules. The good news is that a Sub-module specification has been defined which will allow the interface specification part of a module to be separate from the procedure source code. On[c]e this is implemented in Fortran compilers, it should be utilized by all packaged libraries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.