Hi,
I am building a library project in pure cmake, as generated by qtcreator wizzard:
cmake_minimum_required(VERSION 3.14)
project(testlib LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
add_library(testlib SHARED
testlib_global.h
testlib.cpp
testlib.h
)
target_link_libraries(testlib PRIVATE Qt${QT_VERSION_MAJOR}::Core)
target_compile_definitions(testlib PRIVATE TESTLIB_LIBRARY)
cmake_minimum_required(VERSION 3.14)
project(testlib LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
add_library(testlib SHARED
testlib_global.h
testlib.cpp
testlib.h
)
target_link_libraries(testlib PRIVATE Qt${QT_VERSION_MAJOR}::Core)
target_compile_definitions(testlib PRIVATE TESTLIB_LIBRARY)
To copy to clipboard, switch view to plain text mode
Now I want to compile it from command line without qtcreator.
I do
cmake ..
cmake --build .
cmake ..
cmake --build .
To copy to clipboard, switch view to plain text mode
But it tries to link the x86 build of qt into a x64 target, which fails. I have to add the following line, then it works:
set(CMAKE_PREFIX_PATH "c:\qt\msvc2019_x64")
set(CMAKE_PREFIX_PATH "c:\qt\msvc2019_x64")
To copy to clipboard, switch view to plain text mode
My question: What is the correct way to specify the arch of the Qt library to be linked with cmake? What is the correct way to specify the arch for my library? (Both from pure commandline and not from within Qtcreator...)
Also ... I dont really understand how cmake can find the x86 version of Qt. How does it even know it exists?
Bookmarks