Creating a library
CMake allows you to create libraries, which are indeed used by the OpenCV build system. Factorizing the shared code among multiple applications is a common and useful practice in software development. In big applications or when the common code is shared in multiple applications, this practice is very useful.
In this case, we do not create a binary executable; instead, we create a compiled file that includes all the functions, classes, and so on, developed. We can then share this library file with the other applications without sharing our source code.
CMake includes the add_library
function for this purpose:
# Create our hello library add_library(Hello hello.cpp hello.h) # Create our application that uses our new library add_executable(executable main.cpp) # Link our executable with the new library target_link_libraries( executable Hello )
The lines starting with #
add comments and are ignored by CMake.
The add_library(Hello hello.cpp hello.h)
command defines our new library...