在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. LaTeX技巧004:LaTeX不用添加到目录制作书签技巧

    这里给大家介绍一个命令,需要hyperref宏包.该命令格式如下: \pdfbookmark[]{text}{anchor} \tableofcontents 顺序应该是这样,如果换过来,书签指向的位 ...

  2. Gin_中间件

    gin可以构建中间件,但它只对注册过的路由函数起作用 对于分组路由,嵌套使用中间件,可以限定中间件的作用范围 中间件分为全局中间件,单个路由中间件和群组中间件 gin中间件必须是一个 gin.Hand ...

  3. 区间无修改莫队学习笔记(lg1494小z的袜子)

    这几天感觉要学的要做的有点多,就偷了个懒没写笔记,赶紧补一下 莫队嘛,一个离线处理各种区间(或树上)询问的神奇算法 简单而言,按左端点排个序然后指针l,r递推就好了 复杂度证明貌似是不待修改的n^1. ...

  4. C# asp.net 连接Mysql 数据库

    首先添加 引用: using System.Data;using MySql.Data.MySqlClient; 代码: 这里只写了 后台代码 Mysql 连接和sql 连接代码几乎一样 只要把 My ...

  5. 到头来还是逃不开Java - Java13核心类

    Java13核心类 没有特殊说明,我的所有学习笔记都是从廖老师那里摘抄过来的,侵删 引言 兜兜转转到了大四,学过了C,C++,C#,Java,Python,学一门丢一门,到了最后还是要把Java捡起来 ...

  6. Mysql备份参数

    --all-databases , -A 导出全部数据库. mysqldump -uroot -p --all-databases --all-tablespaces , -Y 导出全部表空间. my ...

  7. numpy Array[:,]的取值方法

  8. Windows下解决github push failed (remote: Permission to userA/XXXX.git denied to userB.) 上传gitHub失败报错

    Windows环境下解决 github push failed (remote: Permission to userA/XXXX.git denied to userB.) · 初学GitHub的朋 ...

  9. spring boot 运行错误: 找不到或无法加载主类

    在项目根目录运行 mvn clean install 进行重新编译 不行的话就删了原有的启动配置,重新配置启动.

  10. 【转载】Pig语法进阶

    转自:http://www.cnblogs.com/siwei1988/archive/2012/08/06/2624912.html Pig Latin是一种数据流语言,变量的命名规则同java中变 ...