Bringing it together – using your libraries
So far, we have created three different libraries – a binary library to be linked either statically or dynamically, an interface or header-only library, and a precompiled but not linked object library.
Let's learn how to use them in an executable in a shared project. Installing them as system libraries or using them as external dependencies will be covered in Chapter 5, Integrating Third-Party Libraries and Dependency Management.
So, we can either put the
add_library calls in the same
CMakeLists.txt file or we can integrate them by using
add_subdirectory. Both are valid options and depend on how the project is set up, as described in the Setting up a project and Working with nested projects sections of this chapter.
In the following example, we're assuming that three libraries have been defined with
CMakeLists.txt files in the
hello_object directories. These libraries can...