Creación de Librerías

Suppose that you want to make a library of the three functions foo1.f, foo2.f, and foo3.f. First, compile them:

     gfortran -c foo1.f
     gfortran -c foo2.f
     gfortran -c foo3.f

This creates the three object files foo1.o foo2.o and foo3.o.
Now use the ar program to create an archive file:

     ar rcv libmylibrary.a foo1.o foo2.o foo3.o
Then you need to fix the table of contents of the new archive:
     ranlib libmylibrary.a
NOTE: For convenience, your library name should start with lib and end with .a as an extension.
Then you can use that library. You need to tell the compiler where to look for libraries, since it is not in one of the standard system directories, and to link against the library. For example, if libmylibrary.a is in the directory:
     /home/ccwf/u1/general/me/foo
You could do something like:
 gfortran -L/home/ccwf/u1/general/me/foo main.f -lmylibrary
When using the -l argument, the compiler assumes that the argument after -l has lib as the first part of the filename and that it has a .a extension. Thus, in this example, it would link against libmylibrary.a.
The -L option tells the linker to look in the directory specified, before looking in the normal system directories, when linking the program.

  • Cómo hacer una biblioteca FORTRAN