首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Windows上查找Qt5 CMake模块

如何在Windows上查找Qt5 CMake模块
EN

Stack Overflow用户
提问于 2013-03-26 22:37:40
回答 6查看 80.8K关注 0票数 47

我正在尝试在Windows上使用CMake创建一个非常基本的Qt5应用程序。我使用的是文档of Qt5 to use CMake,而我的main.cpp文件只包含一个main函数。

我的CMakeLists.txt就是:

代码语言:javascript
运行
复制
cmake_minimum_required(VERSION 2.8.9)

project(testproject)

# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)

# Find the QtWidgets library
find_package(Qt5Widgets)

# Tell CMake to create the helloworld executable
add_executable(helloworld hello.cpp)

# Use the Widgets module from Qt 5.
qt5_use_modules(helloworld Widgets)

在MSysGit bash中,我输入

代码语言:javascript
运行
复制
$ cmake -G"Visual Studio 11"

我得到以下输出:

代码语言:javascript
运行
复制
$ cmake -G"Visual Studio 11"
-- The C compiler identification is MSVC 17.0.60204.1
-- The CXX compiler identification is MSVC 17.0.60204.1
-- Check for working C compiler using: Visual Studio 11
-- Check for working C compiler using: Visual Studio 11 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 11
-- Check for working CXX compiler using: Visual Studio 11 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Warning at CMakeLists.txt:11 (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.


CMake Error at CMakeLists.txt:17 (qt5_use_modules):
  Unknown CMake command "qt5_use_modules".


-- Configuring incomplete, errors occurred!

你有什么想法吗?

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2013-03-27 23:46:36

在台词之后

代码语言:javascript
运行
复制
cmake_minimum_required(VERSION 2.8.9)

project(testproject)

添加

代码语言:javascript
运行
复制
set (CMAKE_PREFIX_PATH "C:\\Qt\\Qt5.0.1\\5.0.1\\msvc2010\\")

这就解决了问题。

票数 42
EN

Stack Overflow用户

发布于 2014-04-10 02:56:43

您应该改为设置CMAKE_PREFIX_PATH环境变量,或者使用cmake-gui来设置Qt5包的路径。

票数 20
EN

Stack Overflow用户

发布于 2016-04-13 18:48:34

您只需将Qt路径添加到Windows %PATH%变量即可。按照官方文档中的建议:http://doc.qt.io/qt-4.8/install-win.html#step-3-set-the-environment-variables

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15639781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档