Ubuntu 安装QT5 后编译程序报错: FindQt5Widgets.cmake

安装QT5.4后,需要编译一个C++程序。 

Cmakelist 有find_package(Qt5Widgets REQUIRED),cmake 报错如下:

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

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

    Qt5WidgetsConfig.cmake
    qt5widgets-config.cmake

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

OverFlow推荐的方法多为添加 CMAKE_PREFIX_PATH 到环境变量。

经过探索,我认为比较简单的方法是: 

在Cmakelist 中设置 Qt5Widgets 路径。

即在Cmakelist 的find_package(Qt5Widgets REQUIRED)前面位置添加

set(Qt5Widgets_DIR /opt/Qt/5.4/gcc_64/lib/cmake/Qt5Widgets)

这里的/opt/Qt/5.4/gcc_64/lib/cmake/Qt5Widgets 是你自己Qt的安装路径。

posted on   lydstory  阅读(1588)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示