Chapter Wrap-up

Let's see what you've learned in this chapter and test your understanding of linking.

We'll cover the following

Summary

Linking in CMake does seem simple and insignificant, but in reality, there's much more to it than meets the eye. After all, linking executables isn't as simple as putting puzzle pieces together. As we learned about the structure of object files and libraries, we discovered that things must move around a bit before a program is runnable. These things are called sections, and they have distinct roles in the life cycle of the program—storing different kinds of data, instructions, symbol names, and so on. A linker needs to combine them together in the final binary accordingly. This process is called relocation.

We also need to take care of symbols—resolve references across all the translation units and make sure that nothing's missing. Then, a linker can create the program header and add it to the final executable. It will contain instructions for the system loader, describing how to turn consolidated sections into segments that make up the runtime memory image of the process.

We also discussed three different kinds of libraries (static, shared, and shared modules), and we explained how they differ and which scenarios fit some better than others. We also touched on the subject of PIC—a powerful concept that allows for the lazy binding of symbols.

Get hands-on with 1400+ tech skills courses.