官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 棋牌| 大石桥市| 根河市| 镶黄旗| 永嘉县| 清苑县| 江北区| 上杭县| 凤冈县| 乌兰浩特市| 安新县| 邵武市| 林周县| 马龙县| 闸北区| 泸西县| 二连浩特市| 夹江县| 通辽市| 东平县| 巴南区| 龙陵县| 乌苏市| 河西区| 天台县| 安义县| 蒙阴县| 吴川市| 奉节县| 肇源县| 丹棱县| 岑巩县| 柞水县| 陆河县| 建始县| 石台县| 嵊泗县| 昔阳县| 寿宁县| 涟水县| 承德县|