This preview shows page 1. Sign up to view the full content.
Unformatted text preview: (In fact, C compiler drivers always pass libc.a to the linker, so the reference to libc.a above is unnecessary.) On Unix systems, static libraries are stored on disk in a particular ﬁle format known as an archive. An archive is a collection of concatenated relocatable object ﬁles, with a header that describes the size and location of each member object ﬁle. Archive ﬁlenames are denoted with the .a sufﬁx. To make our discussion of libraries concrete, suppose that we want to provide the vector routines in Figure 7.5 in a static library called libvector.a. To create the library, we would use the AR tool:
unix> gcc -c addvec.c multvec.c unix> ar rcs libvector.a addvec.o multvec.o To use the library, we might write an application such as main2.c in Figure 7.6, which invokes the addvec library routine. (The include ﬁle vector.h deﬁnes the function prototypes for the routines in libvector.a.) To build the executable, we would compile and link the input ﬁles main.o and libvector.a:
unix> gcc -O2 -c main2.c...
View Full Document
This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.
- Spring '10
- The American