Building different library types
After compiling the source code, it's often desirable to sidestep recompilation for the same platform or even share the compiled output with the external projects. One could distribute the individual object files as initially produced, but this comes with challenges. Distributing multiple files and integrating them one by one into a build system can be a hassle, particularly when dealing with a large number. A more efficient approach is to consolidate all object files into a singular unit for sharing. CMake significantly simplifies this task. We can generate these libraries with a simple add_library()
command (paired with the target_link_libraries()
command).
By convention, all the libraries have a common prefix, lib
, and use system-specific extensions that denote what kind of library they are:
- A static library has a
.a
extension on Unix-like systems and.lib
on Windows. - Shared libraries (and modules) have a
.so
extension on some Unix-like systems...