message(STATUS "OpenCV library status:") message(STATUS " version: ${OpenCV_VERSION}") message(STATUS " libraries: ${OpenCV_LIBS}") message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}") # 添加子目录,该目录为库目录,会调用子目录的cmake文件,进行构建库 add_subdirectory(src) # 构建可执行...
include_directories( ${OpenCV_INCLUDE_DIRS} ${ffmpeg_headers_DIR} ) 添加一个可执行目标,名称可自己指定,本例是直接用工程名称命名的 该可执行目标是由SRC_LIST中所列出的源文件生成 add_executable(${PROJECT_NAME} ${SRC_LIST} ) directory of opencv library link_directories(${OpenCV_LIBRARY_DIRS} $...
message(STATUS "OpenCV library: ${OpenCV_INSTALL_PATH}") message(STATUS " version: ${OpenCV_VERSION}") message(STATUS " libraries: ${OpenCV_LIBS}") message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}") if(${OpenCV_VERSION_MAJOR} GREATER 3) set(CMAKE_CXX_STANDARD 11) endif() else(...
先设置OpenCV_DIR这个变量为OpenCVConfig.cmake文件所在的目录,然后可以直接使用find_package命令找到opencv库,后面就可以使用include_directories以及target_link_libraries命令引入opencv的库。cmake脚本代码如下: set(OpenCV_DIR xxxx) # xxxx目录包含OpenCVConfig.cmake find_package(opencv required) # 找到opencv库 incl...
target_include_directories(Demo PRIVATE ${Abc_INCLUDE_DIRS}) 注:大多数现代的库会同时兼容两种写法,但是建议尽可能用 modern cmake 的面向对象的语法。 库的版本要求 有时候我们需要关注导入库的版本信息,以 OpenCV 为例:导入之后可以通过OpenCV_VERSION变量获取库的版本信息, 在导入时也可以直接限制版本: ...
include_directories(${OpenCV_INCLUDE_DIRS}) add_executable(test opencv.c) target_link_libraries(test ${OpenCV_LIBS}) 说明: SET(CMAKE_C_COMPILER “g++”) SET(CMAKE_CXX_COMPILER “g++”) 以上两行代码用作指定编译器为g++,因为g++支持c++格式,而opencv为c++格式,所以需要进行匹配。
include_directories( ${OpenCV_INCLUDE_DIRS} ) add_executable( DisplayImage DisplayImage.cpp ) #displayimage.cpp是对应的cpp文件名 target_link_libraries( DisplayImage ${OpenCV_LIBS} ) 这样就可以cmake生成工程了。 从这个应用可以看出,其他的CPP库应该也是一样的套路,只要库有对应的cmake文件,并且让cmake...
message(STATUS"OpenCV library status:") message(STATUS"version: ${OpenCV_VERSION}") message(STATUS"libraries: ${OpenCV_LIBS}") message(STATUS"include path: ${OpenCV_INCLUDE_DIRS}") find_package(Torch REQUIRED) include_directories(${OpenCV_INCLUDE_DIRS}) ...
message(STATUS " libraries: ${OpenCV_LIBS}") message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")else(OpenCV_FOUND) message(FATAL_ERROR "OpenCV library not found") endif(OpenCV_FOUND)set(CMAKE_VERBOSE_MAKEFILE on)set(libs "${CMAKE_SOURCE_DIR}/src/main/jniLibs") ...
OpenCV_INCLUDE_DIRS 是头文件路径 OpenCV_LIBS 是库文件地址 有了头文件和库文件,自然而然可以正常引用 OpenCV 了。 package 的通用套路 实际上,通过 find_package() 可以顺利查找任何符合 cmake package 标准的外部工程。 find_pacage()方法签名如下: ...