$ cc | main.c | Compile | to | relocatable code. | |
$ cc | +z f1.c f2.c f3.c | Compile | to |
Figure 24 Example 3: Hidden Definitions: Compiling
Next suppose you put f3.o into the shared library lib3.so and f1.o and f2.o into the archive library lib12.a. Also put f1.o and f2.o into the shared library lib12.so:
$ ld | lib3.so f3.o | Create a | shared | library. | |||
$ ld | lib12.so f1.o f2.o | Create | a | shared | library. | ||
$ ar | qvc lib12.a f1.o f2.o | Create | an archive library. |
Figure 25 Example 3: Hidden Definitions: Mixing Shared and Archive Libraries
Now link the main with the archive library lib12.a and the shared library lib3.so, and create the executable a.out:
$ cc main.o lib12.a lib3.so | Link the program. |
Figure 26 Example 3: Hidden Definitions: Creating the Executable
When you run a.out, it runs correctly. Now, suppose you need to modify f3() to call f2():
Caution When Mixing Shared and Archive Libraries 123