O and is the same for all c programs figure 714 shows

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: unix> gcc -static -o p2 main2.o ./libvector.a Figure 7.7 summarizes the activity of the linker. The -static argument tells the compiler driver that the linker should build a fully-linked executable object file that can be loaded into memory and run without 7.6. SYMBOL RESOLUTION 363 code/link/addvec.c 1 2 3 4 5 6 7 8 code/link/multvec.c 1 2 3 4 5 6 7 8 void addvec(int *x, int *y, int *z, int n) { int i; for (i = 0; i < n; i++) z[i] = x[i] + y[i]; } code/link/addvec.c void multvec(int *x, int *y, int *z, int n) { int i; for (i = 0; i < n; i++) z[i] = x[i] * y[i]; } code/link/multvec.c (a) addvec.o (a) multvec.o Figure 7.5: Member object files in libvector.a. code/link/main2.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 /* main2.c */ #include <stdio.h> #include "vector.h" int x[2] = {1, 2}; int y[2] = {3, 4}; int z[2]; int main() { addvec(x, y, z, 2); printf("z = [%d %d]\n", z[0], z[1]); return 0; } code/link/main2.c Figure 7.6: Example program 2: This program c...
View Full Document

Ask a homework question - tutors are online