|
|
1.1 ! root 1: .TI F77/USERLIBS "Sep. 15, 1984" ! 2: Making Random Libraries from Object Files ! 3: ! 4: A library is a single file which contains many different object files ! 5: plus an index to the contents of the library. In UNIX, libraries are ! 6: "archives" and have names ending in ".a". When loading, only the ! 7: needed object files are loaded from libraries mentioned in the f77 ! 8: command. To load a program requiring object files from library file ! 9: "mylib.a" in the current directory, type: ! 10: ! 11: f77 prog.o sub1.o ... mylib.a ! 12: ! 13: This loads the object files prog.o, sub1.o, etc. and then loads those ! 14: object files in mylib.a that prog.o, sub1.o, ... reference. ! 15: ! 16: Library names are listed at the end of the f77 command because ! 17: object files in the libraries are loaded only if the object files ! 18: are referenced by previously loaded object files. ! 19: ! 20: The "ar" command creates and maintains archives on UNIX. Here ! 21: is a simple example that compiles three subroutines and adds them ! 22: to the archive mylib.a: ! 23: ! 24: .nf ! 25: f77 -c sub1.f sub2.f sub3.f ! 26: ar uv mylib.a sub1.o sub2.o sub3.o ! 27: .fi ! 28: ! 29: Ar will respond with "a - sub.o" when a file is first inserted (appended) into ! 30: the archive. ! 31: We could use the same ar command to replace already existing ! 32: object files in the archive. Ar responds with "r - sub.o" when a file is ! 33: updated (replaced) in the archive. ! 34: ! 35: Use ranlib to add a random table of contents to the archive, converting it to a ! 36: library: ! 37: ! 38: ranlib mylib.a ! 39: ! 40: To see what .o files are in a library or archive, type: ! 41: ! 42: ar tv mylib.a ! 43: ! 44: To see what subprograms, entry points, and common blocks are referenced ! 45: by the .o files in an archive, type: ! 46: ! 47: nm -g mylib.a ! 48: ! 49: The loader checks whether the random index of a library is up to date ! 50: or not by comparing the date within the file to the modification date ! 51: of the file. Because of this, if you use the 'cp' command to make a ! 52: second copy of a library, the loader thinks the random index for the ! 53: library is out of date, ignores it and issues a warning: ! 54: ! 55: .nf ! 56: % cp libnew.a mylib.a ! 57: % f77 prog.o mylib.a ! 58: ld:mylib.a: warning: table of contents for archive is out ! 59: of date; rerun ranlib(1) ! 60: .fi ! 61: ! 62: Instead, either use the 'mv' command if you just want to change the ! 63: name or path of the library, ! 64: or use the 'tar' command if you really want to make an identical copy. ! 65: To use 'tar', first move into the directory containing the library. ! 66: Then issue the command: ! 67: ! 68: tar cBf - libnew.a | ( cd ~/newdir ; tar xBf - libnew.a ) ! 69: ! 70: This copies libnew.a to ~/newdir/libnew.a. Tar creates the new file ! 71: with the same modification date as the original file so that you do ! 72: not need to rerun ranlib. Notice that the name of the library, libnew.a, ! 73: appears twice in the command line and must be identical in both positions. ! 74: If you want the copy of the library to have a different name, follow ! 75: the tar with a mv command. ! 76: ! 77: To copy a library across systems, use tar together with rsh; e.g. to ! 78: copy mylib.a on opal to ~/mybin/mylib.a on populi, type the ! 79: following on opal: ! 80: ! 81: .nf ! 82: tar cBf - mylib.a \\ ! 83: | rsh populi "( cd mybin; tar xBf - mylib.a )" ! 84: .fi ! 85: ! 86: For large libraries, you may want to check if there were transmission errors ! 87: by comparing the copy to the original: ! 88: ! 89: rsh populi cat mylib.a | cmp - mylib.a ! 90: ! 91: For more information, see ar(1), ld(1), nm(1), ranlib(1), and rsh(1) in the ! 92: UNIX Programmer's Manual. ! 93: ! 94: For information of importance in dealing with large libraries, see "help ! 95: f77 biglibs".
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.