You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CMake GUI配置项目时Qt6兼容错误排查求助

Qt6 CMake配置错误分析及解决

错误详情

CMake Error at CMakeLists.txt:11 (find_package):
Could not find a configuration file for package "Qt6" that is compatible
with requested version "".

The following configuration files were considered but not accepted:

C:/Qt/6.3.1/mingw_64/lib/cmake/Qt6/Qt6Config.cmake, version: 6.3.1 (64bit)

提供的CMakeLists.txt代码:

cmake_minimum_required(VERSION 3.22)
project(environment_PO)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(CMAKE_PREFIX_PATH "C:/Qt/6.3.1/mingw_64")

find_package(Qt6 COMPONENTS
        Core
        Gui
        Widgets
        REQUIRED)

add_executable(environment_PO main.cpp mainWindow.h mainWindow.cpp datetime.h datetime.cpp generateSubjectCode.h generateSubjectCode.cpp loadSettings.h loadSettings.cpp saveSettings.h saveSettings.cpp)
target_link_libraries(environment_PO
        Qt6::Core
        Qt6::Gui
        Qt6::Widgets
        )

问题原因

错误核心是CMake与Qt的架构不匹配:你安装的Qt是64位版本(路径中的mingw_64标识),但当前使用的CMake GUI是32位程序。CMake查找依赖时会默认匹配自身架构,因此直接拒绝了64位的Qt配置文件,哪怕文件确实存在。

解决方案

  • 更换64位CMake:下载并使用对应平台的64位CMake GUI,重新配置项目,此时CMake会自动识别64位Qt安装包,无需修改现有配置。
  • 更换32位Qt:如果需要保留当前32位CMake,安装Qt的32位版本(对应安装包中的mingw_32分支),然后修改CMakeLists.txt中的CMAKE_PREFIX_PATH为C:/Qt/6.3.1/mingw_32。
  • 强制指定架构(临时方案):在CMake GUI中点击"Add Entry",添加变量CMAKE_SIZEOF_VOID_P,设置值为8(代表64位),然后重新配置。注意这种方法可能引发后续编译的架构冲突,仅作为临时测试使用。

内容的提问来源于stack exchange,提问作者LoveAndMercy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 21:45:35