Creating a library
CMake allows us to create libraries used by the OpenCV build system. Factorizing shared code among multiple applications is a common and useful practice in software development. In big applications, or common code shared in multiple applications, this practice is very useful. In this case, we do not create a binary executable, but instead we create a compiled file that includes all the functions, classes, and so on. We can then share this library file with other applications without sharing our source code.
CMake includes the add_library function to this end:
# 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 the source files of our library and its name, where Hello is the library name and hello.cpp and hello.h are the source files. We add the header file too to allow IDEs such as Visual Studio to link to the header files. This line is going to generate a shared (.so for Mac OS X, and Unix or .dll for Windows) or static library (.a for Mac OS X, and Unix or .lib for Windows) file, depending on whether we add a SHARED or STATIC word between library name and source files. target_link_libraries(executable Hello) is the function that links our executable to the desired library, in our case, the Hello library.
- SQL入門經典(第5版)
- 輕松學大數據挖掘:算法、場景與數據產品
- UDK iOS Game Development Beginner's Guide
- Creating Dynamic UIs with Android Fragments(Second Edition)
- 智能數據分析:入門、實戰與平臺構建
- The Game Jam Survival Guide
- 白話大數據與機器學習
- R語言數據挖掘
- 深入理解InfluxDB:時序數據庫詳解與實踐
- 云計算寶典:技術與實踐
- 信息融合中估計算法的性能評估
- Scratch 2.0 Game Development HOTSHOT
- SOLIDWORKS 2018中文版機械設計基礎與實例教程
- AI Crash Course
- 數據可視化五部曲