新 CLion 项目中的 QT6 编译错误

时间:2021-05-16 16:29:17

标签: qt cmake clion

我尝试使用 CLion 制作 QT 项目,我安装了 QT6,我只想运行一个基本的“helloworld”(以确保我的配置没问题)。但是我遇到了一些问题,我的 CLion 问题终端是空的,但是当我尝试运行代码时出现此错误:

"D:\CLion 2021.1.1\bin\cmake\win\bin\cmake.exe" --build D:\Qt\6.0.2\mingw81_64\bin --target GameRegister -- -j 12
Scanning dependencies of target GameRegister_autogen
[ 20%] Automatic MOC and UIC for target GameRegister
[ 20%] Built target GameRegister_autogen
Scanning dependencies of target GameRegister
[ 40%] Building CXX object CMakeFiles/GameRegister.dir/GameRegister_autogen/mocs_compilation.cpp.obj
[ 60%] Building CXX object CMakeFiles/GameRegister.dir/main.cpp.obj
[ 80%] Building CXX object CMakeFiles/GameRegister.dir/gameregister.cpp.obj
[100%] Linking CXX executable GameRegister.exe
Error copying file "D:/Qt/6.0.2/mingw81_64/lib/cmake/../../bin/Qt6Cored.dll" to "D:/Qt/6.0.2/mingw81_64/bin".
mingw32-make.exe[3]: *** [CMakeFiles\GameRegister.dir\build.make:141: GameRegister.exe] Error 1
mingw32-make.exe[3]: *** Deleting file 'GameRegister.exe'
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:95: CMakeFiles/GameRegister.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:102: CMakeFiles/GameRegister.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:136: GameRegister] Error 2

为了进行配置,我遵循了本指南 https://www.jetbrains.com/help/clion/qt-tutorial.html#issues-limits

我还查看了 Qt 文档来制作我的 CMakeLists.txt。

我的 CMakeLists.txt :

cmake_minimum_required(VERSION 3.19)
project(GameRegister)

#Cmake with 20cpp version
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

#QT version
set(QT_VERSION 6)
set(REQUIRED_LIBS Core)
set(REQUIRED_LIBS_QUALIFIED Qt6::Core)

add_executable(${PROJECT_NAME}
        main.cpp gameregister.cpp
        gameregister.h
        gameregister.ui
)

#Path to cmake lib in QT
set(CMAKE_PREFIX_PATH "D:/Qt/6.0.2/mingw81_64/lib/cmake")

if (NOT CMAKE_PREFIX_PATH)
    message(WARNING "CMAKE_PREFIX_PATH is not defined, you may need to set it "
            "(-DCMAKE_PREFIX_PATH=\"path/to/Qt/lib/cmake\" or -DCMAKE_PREFIX_PATH=/usr/include/{host}/qt{version}/ on Ubuntu)")
endif ()

#Find necessary packages
find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED)
find_package(Qt${QT_VERSION} COMPONENTS Widgets REQUIRED)

#Target packages
target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED})
target_link_libraries(${PROJECT_NAME} Qt6::Widgets)

#auto generated by CLion on creation
if (WIN32)
    set(DEBUG_SUFFIX)
    if (CMAKE_BUILD_TYPE MATCHES "Debug")
        set(DEBUG_SUFFIX "d")
    endif ()
    set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}")
    if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
        set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
        if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
            set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
        endif ()
    endif ()
    if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll")
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E make_directory
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll"
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
    endif ()
    foreach (QT_LIB ${REQUIRED_LIBS})
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                "${QT_INSTALL_PATH}/bin/Qt${QT_VERSION}${QT_LIB}${DEBUG_SUFFIX}.dll"
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>")
    endforeach (QT_LIB)
endif ()

这是我的运行/调试配置: enter image description here

所以我不知道为什么会出现此错误,也许我的路径之一不正确,或者我需要编辑运行/调试的配置?

0 个答案:

没有答案