在windows下写好CMakeLists.txt,然后配合cmake-gui使用。

CMakeLists.txt写的不够好,后期优化,以下仅供参考:

 # set(OpenCV_DIR D:/Program Files/opencv3.4.6/opencv/build/include/)
find_package(OpenCV 3.4. REQUIRED) # If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
set(LINK_DIR D:/windows/x64/Release/)
# Add OpenCV headers location to your include paths
include_directories(${OpenCV_INCLUDE_DIRS}) # Declare the executable target built from your sources aux_source_directory(. DIR_SRCS)
add_executable(main ${DIR_SRCS}) # Link your application with OpenCV libraries
# link_libraries("D:/windows/x64/Release")
LINK_DIRECTORIES(${LINK_DIR}) #链接静态库目录
target_link_libraries(main ${OpenCV_LIBS} ${LINK_DIR}/idcard.lib)

由于依赖opencv静态库,opencv又没有设置为环境变量,cmake直接找依赖opencv时总是会找到Anaconda里面的opencv,此时需要把opencv路径指定到你编译opencv静态库的路径:

也可以将CMakeLists.txt写成下面的形式,这样就可以自己在cmake-gui里面自己配置需要链接的静态库路径:

 # cmake needs this line
cmake_minimum_required(VERSION 2.8) # Define project name
project(DLCropTest) # Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
# set(OpenCV_DIR D:/Program Files/opencv3.4.6/opencv/build/include/)
find_package(OpenCV REQUIRED)
find_library(LINK_DIR REQUIRED)
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
# set(LINK_DIR D:/windows/x64/Release/)
# Add OpenCV headers location to your include paths
include_directories(${OpenCV_INCLUDE_DIRS}) # Declare the executable target built from your sources aux_source_directory(. DIR_SRCS)
add_executable(main ${DIR_SRCS}) # Link your application with OpenCV libraries
# link_libraries("D:/windows/x64/Release")
LINK_DIRECTORIES(${LINK_DIR}) #链接静态库目录
target_link_libraries(main ${OpenCV_LIBS} ${LINK_DIR}/*.lib)

cmake-gui对应位置如下图:

windows CMakeLists.txt的更多相关文章

  1. [Windows篇] 在windows 10上源码编译gtest 并编写CMakeLists.txt

    本文首发于个人博客https://kezunlin.me/post/aca50ff8/,欢迎阅读! compile gtest on windows 10 Guide compile gtest on ...

  2. opencv3在CMakeLists.txt中的调用问题

    在cmake工程中使用opencv需要在CMakeLists.txt文件中加以调用,在opencv2.xx版本,可以用以下语句 # 寻找OpenCV库 find_package( OpenCV REQ ...

  3. linux CMakeLists.txt 语法

    CMake入门教程 参考文献:http://www.ibm.com/developerworks/cn/linux/l-cn-cmake/index.html 官方网址:http://www.cmak ...

  4. CMake之CMakeLists.txt编写入门

    自定义变量 主要有隐式定义和显式定义两种. 隐式定义的一个例子是PROJECT指令,它会隐式的定义< projectname >_BINARY_DIR和< projectname & ...

  5. CMakeLists.txt编写常用命令

    目录 1. 设置cmake最小版本 2. 设置项目名称 3. 设置编译目标类型 4. 指定编译包含的源文件 1. 明确指明包含的源文件 2. 搜索指定目录的所有的cpp文件 3. 自定义搜索规则 4. ...

  6. CMakeLists.txt install

    本部分是关于ros CMakeLists.txt install  :可参考http://wiki.ros.org/catkin/CMakeLists.txt 1.CMakeLists.txt中的in ...

  7. 简单CMakeLists.txt文件

    #CMakeLists.txt cmake_minimum_required(VERSION 2.8) project(server) #添加包含目录 include_directories(./in ...

  8. CMAKE 生成VS2008静态库工程 与 CMAKE使用,CMakeLists.txt编写总结

    cmake -G"Visual Studio 9 2008 Win64" 以上命令得用cd命令切换到顶层CMakeLists.txt的当前目录,才能生效 以下是CMakeLists ...

  9. Android Studio Linking an external C++ project 时候 报Invalid file name. Expected: CMakeLists.txt

    Android Studio 右键Linking an external C++ project 时候 报Invalid file name. Expected: CMakeLists.txt错误 查 ...

随机推荐

  1. HDU-1506 Largest Rectangle in a Histogram【单调栈】

    Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...

  2. Vuex项目实战store

    首先简单了解一下什么是Vuex? Vuex是一个专为Vue.js应用程序开发的状态管理模式.采用集中式存储来管理应用所有组件的状态. 以下是对vuex的使用的简单介绍: 一.安装 npm i vuex ...

  3. [BOI2003] Gem - 树形dp

    结论 不同颜色数不会超过 \(O(\log n)\) 然后就是很简单的树形dp了 顺便复习一下树形dp怎么写 #include <bits/stdc++.h> using namespac ...

  4. Java 11 新垃圾回收器 ZGC

    可伸缩.低延迟的垃圾回收器 GC 暂停时间不超过 10ms 堆管理容量范围(小M级别,大到T级别) 对应用吞吐量影响不超过15%(对比 G1) 为进一步的添加新特性和优化做基础 默认支持 Linux/ ...

  5. react 渲染

    目录 React渲染 createElement的三个参数 element如何生成真实节点 ReactDOMComponent 作用 ReactCompositeComponentWrapper 作用 ...

  6. php server整理

    $_SESSION['PHP_SELF'] -- 获取当前正在执行脚本的文件名. $_SERVER['SERVER_PROTOCOL'] -- 请求页面时通信协议的名称和版本.例如,“HTTP/1.0 ...

  7. 设置一个数量不定item的位置

    let dis;//item宽度加item之间gap的宽度item.setPosition((i<arr.length/2?-1:1) * Math.abs(i - arr.length/2 + ...

  8. Docker(二)Image 与网络

    Docker Image 我们介绍一下如何构造一个自定义的 Docker  Image.在Docker 中,我们使用Dokcerfile 构建一个docker的描述. 首先我们定义一下需要启动一个什么 ...

  9. 图的最短路径算法-- Floyd算法

    Floyd算法求的是图的任意两点之间的最短距离 下面是Floyd算法的代码实现模板: ; ; // maxv为最大顶点数 int n, m; // n 为顶点数,m为边数 int dis[maxv][ ...

  10. CrystalDecisions.Windows.Forms文件

    1.CrystalDecisions.Windows.Forms 相关dll文件 CrystalDecisions.Crystalreports.Engine.dllCrystalDecisions. ...