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

以上;

原创,转载请注明出处;

相关推荐
查古穆10 分钟前
python进阶-Pydantic模型
开发语言·python
沐知全栈开发13 分钟前
Bootstrap4 导航栏
开发语言
kyriewen1116 分钟前
异步编程:从“回调地狱”到“async/await”的救赎之路
开发语言·前端·javascript·chrome·typescript·ecmascript·html5
AI+程序员在路上19 分钟前
嵌入式软件技术大全
linux·开发语言·arm开发·单片机
吴声子夜歌19 分钟前
JavaScript——数据类型
开发语言·javascript·ecmascript
2401_8796938739 分钟前
C++中的观察者模式实战
开发语言·c++·算法
工頁光軍1 小时前
基于Python的Milvus完整使用案例
开发语言·python·milvus
wregjru1 小时前
【网络】8.五种 I/O 模型与多路转接详解
开发语言·php
fff9811181 小时前
C++与Qt图形开发
开发语言·c++·算法
xht08321 小时前
PHP vs Python:编程语言终极对决
开发语言·python·php