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.oThen you need to fix the table of contents of the new archive:
ranlib libmylibrary.aNOTE: For convenience, your library name should start with lib and end with .a as an extension.
/home/ccwf/u1/general/me/fooYou could do something like:
gfortran -L/home/ccwf/u1/general/me/foo main.f -lmylibraryWhen 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.