- OpenCV By Example
- Prateek Joshi David Millán Escrivá Vinícius Godoy
- 252字
- 2021-07-23 14:41:59
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 called, where Hello
is the library name and hello.cpp
, hello.h
are the source files. We add the header file to allow IDEs such as Visual Studio to link to the header files.
This line will generate a shared file (So for OS X and Unix or .dll
for Windows) or a static library (A for OS X and Unix or .dll
for Windows), depending on our operating system or if it is a dynamic or static library.
target_link_libraries( executable Hello)
is the function that links our executable to the desired library; in our case, it's the Hello
library.
- 樂學Web編程:網站制作不神秘
- Programming ArcGIS 10.1 with Python Cookbook
- INSTANT Weka How-to
- Julia高性能科學計算(第2版)
- Android移動開發案例教程:基于Android Studio開發環境
- Building Serverless Architectures
- Advanced Python Programming
- MySQL 8從零開始學(視頻教學版)
- 算法秘籍
- 透視C#核心技術:系統架構及移動端開發
- 現代JavaScript編程:經典范例與實踐技巧
- 3ds Max瘋狂設計學院
- 深入淺出Rust
- React Router Quick Start Guide
- Visual FoxPro程序設計(第二版)