Holger
Holger

Reputation: 2175

Distribute compiled fortran library with module files

I have a Fortran library that uses a lot of modules. I use the ifort compiler on Windows. Therefore, I get a *.lib file for the library and *.mod files for the used modules.

This has the disadvantage that I also have to distribute the *.mod files, if I want to use the compiled library in another programme. How can this be prevented? I see two possibilities:

  1. Create an interface, where functions are defined that are used to call the functions or procedures inside the library modules. So, I only have to provide the file, where the interface is defined.
  2. Use the c-interface and export names for all module functions and procedures that should be used from outside the library using bind(c) in function definitions. Then I can distribute the library with a c-like header file.

Are there any other possibilities? What are best practices to distribute a compiled fortran library that uses modules?

Upvotes: 2

Views: 808

Answers (1)

I think that to distribute also the .mod file is the easiest, by far, if it supposed to by used called from Fortran. If it is to be called from other languages, you need the C interface anyway.

The bad thing is loosing the Fortran explicit interfaces. With option number 1 you can probably still have it, if you supply an include file with interface blocks, but just supplying the .mod file is better IMHO.

Upvotes: 1

Related Questions