windows下,用CMake编译qt项目,出现错误By not providing “FindQt5.cmake“...

开发环境:windows10 + qt5.14, 编译器msvc2017x64,CMake3.30;

现象:

CMakeList文件里,如有find_package(Qt5 COMPONENTS Widgets REQUIRED)

target_link_libraries(dis_lib PRIVATE Qt5::Widgets)

用CMake生成工程时候,会有如下错误:

CMake Error at CMakeLists.txt:69 (find_package):
By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5", but
CMake did not find one.

Could not find a package configuration file provided by "Qt5" with any of
the following names:

Qt5Config.cmake
qt5-config.cmake

Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
to a directory containing one of the above files. If "Qt5" provides a
separate development package or SDK, be sure it has been installed.

解决方法:

1.在qt安装目录搜索Qt5Config.cmake,找到文件路径;

2.在系统环境变量-用户变量里,添加Qt5_DIR=文件路径;如下图,然后保存

3.重新CMake即可;

以上;

原创,转载请注明出处;

相关推荐
小羊没烦恼!7 小时前
初探性能优化——2个月到4小时的性能提升
java·开发语言·windows·算法·c#
伞伞悦读8 小时前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
C语言小火车8 小时前
C/C++ 为什么需要编译器?
开发语言·c++
霍霍的袁9 小时前
【C++】map 和 set 的使用 | 从用法到底层
开发语言·c++·学习·visual studio
孙启超10 小时前
【AI开发之Rust】第 11 课:智能指针与内部可变性
开发语言·后端·rust
此生决int10 小时前
深入理解C++系列(20)——C++11(下)
开发语言·c++
慧都小项10 小时前
当边缘AI上产线:QtitanDocking 如何让工业 HMI 实现多视图协同
人工智能·qt·ui·边缘计算·qt6.3
CoderYanger11 小时前
A.每日一题:835. 图像重叠
java·开发语言·程序人生·leetcode·面试·职场和发展·学习方法
伞伞悦读12 小时前
【第37期】Python JSON 与配置详解:序列化、反序列化、嵌套结构和配置文件
开发语言·python·json
CCCCCCCCharlie12 小时前
Linux进程控制四大核心操作
linux·开发语言