CMake Qt配置Halcon
下面讲解如何引入Halcon的include和lib
CMakeLists.txt内容
################################# 1、最低CMake版本 cmake_minimum_required(VERSION 3.5) ################################# 2、项目名qtCmake project(qtCmake LANGUAGES CXX) ################################# 3、set模块 set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) # 设置exe生成路径。喜欢用CMAKE_CURRENT_SOURCE_DIR,指CMakeLists.txt所在的路径 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/build/) # 设置c++语言支持 set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) ################################# 4、查找依赖的Qt文件 find_package(Qt5 COMPONENTS Widgets REQUIRED) #配置halcon,include、lib目录,具体的lib在target_link_libraries里(注意不加.lib后缀) #系统环境变量$ENV,也可以换成自己的绝对路径 include_directories("$ENV{HALCONROOT}/include" "$ENV{HALCONROOT}/include/halconcpp") link_directories("$ENV{HALCONROOT}/lib/$ENV{HALCONARCH}") ################################# 5、生成qtHalcon.exe add_executable(qtHalcon main.cpp widget.cpp widget.h) target_link_libraries(qtHalcon PRIVATE Qt5::Widgets halcon halconcpp)
include的意义,include路径后,就不需要#include“一长串路径/HalconCpp.h”