I am not a very expert Fortran programmer, but now that I have written many subroutines (in Fortran 90), I have to put them in Modules (employed by "use" statement in other subroutines and program) to avoid writing the interfaces. I have to use these modules with old code written in F77. I don't want the compiler to compile these modules again and again. So I created a static library from the ".o" files after compiling these modules:
ar rc libmymath.a module1.o module2.o module3.o
However I still need to keep the ".mod" files of these modules to be able to "use" them in my code.
My question: is it possible to pack these ".mod" files in the static library archive ".a" (as we did with .o files), so that everything is encapsulated in the single file static library?
P.S: by anywhere I mean across my systems, all of them use gfortran 64 bit.
Using a Module into your Program You can add as many modules as needed, each will be in separate files and compiled separately. A module can be used in various different programs. A module can be used many times in the same program. The variables declared in a module specification part, are global to the module.
The linker reads individual object files and libraries, resolves references to external symbols, and writes out a single executable file or dynamic link library. The linker can also create a map file containing information about the segments and public symbols in the program.
A software library is usually a set of subprograms that have been previously compiled and organized into a single binary library file. Each member of the set is called a library element or module.
No, it is not possible.
In an analogue to C/C++, a .mod
file is like a header file. It describes the contents of the module and the USE <module>
is similar to the #include <header>
.
These mod files are compiler (and often even version) specific and are required because modules name-mangle the functions and so there needs to be a lookup table for the resulting function names.
You just copy those .mod files
to your fortran finclude directory
.
e.g I am using ubuntu
with gcc -4.4.3
. What i did is I have copied the library librandom.a
to /usr/local/lib
and the mod file random.mod
to /usr/lib/gcc/i486-linux-gnu/finclude
.
Now I don't have to create those mods again and again . I just have to use gfortran -o myfile myfile.f90 -lrandom
to compile my program and link with the library. Of course i have to use "use random " in my myfile.f90.
Cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With