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即可;

以上;

原创,转载请注明出处;

相关推荐
blasit2 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
郑州光合科技余经理6 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
feifeigo1237 天前
matlab画图工具
开发语言·matlab
dustcell.7 天前
haproxy七层代理
java·开发语言·前端
norlan_jame7 天前
C-PHY与D-PHY差异
c语言·开发语言
多恩Stone7 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
QQ4022054967 天前
Python+django+vue3预制菜半成品配菜平台
开发语言·python·django
遥遥江上月7 天前
Node.js + Stagehand + Python 部署
开发语言·python·node.js
m0_531237177 天前
C语言-数组练习进阶
c语言·开发语言·算法
Railshiqian7 天前
给android源码下的模拟器添加两个后排屏的修改
android·开发语言·javascript