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的安装路径。

猜你喜欢

转载自www.cnblogs.com/hshy/p/8966053.html
今日推荐