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

以上;

原创,转载请注明出处;

相关推荐
枫叶丹413 分钟前
【Qt开发】Qt系统(一)-> 定时器 QTimerEvent 和 QTimer
c语言·开发语言·数据库·c++·qt·系统架构
林政硕(Cohen0415)1 小时前
ARM Linux Qt Widget 虚拟键盘输入法移植
linux·arm开发·qt·键盘·输入法
我居然是兔子6 小时前
异常练习:在试错中吃透Java异常处理的底层逻辑
java·开发语言
养一回月亮!7 小时前
使用Qt实现简单绘图板:鼠标绘制与擦除功能详解
开发语言·qt
BanyeBirth7 小时前
C++差分数组(二维)
开发语言·c++·算法
Tony Bai7 小时前
Go 的 AI 时代宣言:我们如何用“老”原则,解决“新”问题?
开发语言·人工智能·后端·golang
Fcy6487 小时前
C++ map和multimap的使用
开发语言·c++·stl
L Jiawen8 小时前
【Golang基础】基础知识(下)
服务器·开发语言·golang
云栖梦泽8 小时前
鸿蒙应用AI赋能与国际化落地实战:让待办应用跨越语言与智能边界
开发语言·鸿蒙系统
CoderCodingNo9 小时前
【GESP】C++五级真题(结构体排序考点) luogu-B3968 [GESP202403 五级] 成绩排序
开发语言·c++·算法