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.
/home/ccwf/u1/general/me/foo
You 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.