Let's learn about how to link libraries in CMake.

You might think that after we have successfully compiled the source code into a binary file, our job as build engineers is done. That's almost the case—binary files contain all the code for a CPU to execute, but the code is scattered across multiple files in a very complex way. Linking is a process that simplifies things and makes machine code neat and quick to consume.

Linking support in CMake

A quick glance at the list of commands will tell us that CMake doesn't provide that many related to linking. Admittedly, target_link_libraries() is the only one that configures this step. Why dedicate a whole chapter to a single command, then? Unfortunately, almost nothing is ever easy in computer science, and linking is no exception.

Get hands-on with 1200+ tech skills courses.