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.


環境 qt5.12.3  deepin15.10

cmake構建

由於之前使用的是倉庫自帶的qt環境,后來需要更高版本qt,於是從官網下載安裝器自己安裝,重新構建之后便出現這個問題,具體報錯如下

CMake Warning at src/CMakeLists.txt:45 (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.

我去翻看了cmake官方文檔,然后看到一篇文章才明白,cmake在find_package的時候需要提供對應模塊的*.cmake文件,根據推測要么是cmake自己提供,顯然不是,於是在我的qt安裝目錄下找到相應目錄提供給cmake查找

在我的qt安裝路徑下的"/opt/Qt/5.12.3/gcc_64/lib/cmake"里面便可以找到提供給cmake的各個模塊的文件夾,每個文件夾下提供了對應的*.cmake文件。這篇文章給我的答案:https://stackoverflow.com/questions/15639781/how-to-find-the-qt5-cmake-module-on-windows#

我是這樣做的

set(CMAKE_PREFIX_PATH "/opt/Qt/5.12.3/gcc_64")
為每個模塊提供*.cmake文件搜索路徑
set(Qt5_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5")
set(Qt5Widgets_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5Widgets")
set(Qt5Network_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5Network")
set(Qt5LinguistTools_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5LinguistTools")
然后查找
find_package(Qt5 COMPONENTS Widgets Network LinguistTools)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM