D
D
dalbio2022-03-17 23:19:04
Qt
dalbio, 2022-03-17 23:19:04

How to connect qt to a project using cmake?

I seem to have everything connected in the cmake file itself, but when connecting QImage, for some reason, it gives an error about an unresolved external symbol. Maybe I'm wrong somewhere, tell me what's wrong

cmake_minimum_required(VERSION 3.19)
project(FictionalSystem)
set(username $ENV{USERNAME})

set(CMAKE_CXX_STANDARD 17)


set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH "C:\\Qt\\6.1.3\\mingw81_64\\lib\\cmake")
set(EXECUTABLE_OUTPUT_PATH "..\\..\\..\\release")

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(Qt6Widgets REQUIRED)
find_package(Qt6 COMPONENTS Gui REQUIRED)



include_directories(${Qt6Widgets_INCLUDES})


if (MSVC)
        message("yes")
endif()






#add_library (
#    PICS 
#    "src/pics/set/pics.h"
#    "src/pics/set/lbp.h"
#)

#add_library (
#    NET
    #"src/net/templates/algen.h"
    #"src/net/countmask.h"
    #"src/net/structure/prefim.h"
    #"src/net/templates/create_w.h"
#)
add_library(
    LEARNING
    "src/learning/adaboost.h"
    "src/learning/countmask.h"
   # "src/learning/create_w.h"
)
add_library(
    STRUCT
    "src/struct/algen.h"
    "src/struct/prefim.h"
    "src/struct/shab.h"
    "src/struct/sigmoid.h"
)





add_library(
    SRC
    "src/learning.h"
    "src/net.h"
    "src/pics_get.h"
    "src/pics_set.h"
)
add_executable(fict main.cpp ${SRC})

add_library(mytarget)

target_link_libraries(mytarget PRIVATE Qt6::Gui)


target_link_libraries(fict Qt6::Widgets)


Structure: (net directory not used)6234cb309c5c4829564610.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2022-03-18
@dalbio

If you are using the QImage class, then the official documentation says which lines to add to CMakeLists.txt ( https://doc.qt.io/qt-6/qimage.html ):

find_package(Qt6 COMPONENTS Gui REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Gui)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question