CMake报错处理:Could not find a package configuration file provided by “QT“ with any of

今天使用cmake来管理qt项目,遇到一些报错,在此记录一下

目录

1. Qtcreator创建cmake类型的控制台程序

2.使用Cmake-gui构建vs2012项目

2.1 创建build构建目录

2.2 CMake-gui构建

2.3 报错

(1)解决办法1

(2)解决办法2


1. Qtcreator创建cmake类型的控制台程序

我安装的qt市6.4.1和6.5.0版本

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第1张图片

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第2张图片

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第3张图片

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第4张图片

使用MSVC2019编译器

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第5张图片

由于本机没有安装msvc2019编译器,导致项目出现问题

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第6张图片

切换编译器

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第7张图片

切换后程序正常执行

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第8张图片

2.使用Cmake-gui构建vs2012项目

2.1 创建build构建目录

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第9张图片

2.2 CMake-gui构建

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第10张图片

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第11张图片

2.3 报错

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第12张图片

报错提示内如下:

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第13张图片

通过错误显示找不到以下cmake文件

Qt6Config.cmake
qt6-config.cmake
Qt5Config.cmake
qt5-config.cmake

解决办法也给出来了,我安装的qt6,所以只需要查找Qt6Config.cmake 或者
qt6-config.cmake所在路径

qt6-config.cmake找不到

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第14张图片

Qt6Config.cmake查找到了,查找对应编译器为 C:\Qt\6.5.0\mingw_64\lib\cmake\Qt6

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第15张图片

(1)解决办法1

CMAKE_PREFIX_PATH中添加路径C:\Qt\6.5.0\mingw_64\lib\cmake\Qt6

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第16张图片

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第17张图片

编译OK,生成了vs2012项目工程

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第18张图片

(2)解决办法2

QT_DIR和Qt6_DI设置C:\Qt\6.5.0\mingw_64\lib\cmake\Qt6

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第19张图片

生成OK

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第20张图片

CMake报错处理:Could not find a package configuration file provided by “QT“ with any of_第21张图片

你可能感兴趣的:(cmake,qt,cmake)