c++ - 如何在 Windows 上找到 Qt5 CMake 模块

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

我的 CMakeLists.txt 正是:

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 时

$ cmake -G"Visual Studio 11"

我得到这个输出:

$ 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!

你有什么想法吗?

最佳答案

行后

cmake_minimum_required(VERSION 2.8.9)

project(testproject)

添加

set (CMAKE_PREFIX_PATH "C:\\Qt\\Qt5.0.1\\5.0.1\\msvc2010\\")

这样就解决了问题。

https://stackoverflow.com/questions/15639781/

相关文章:

c++ - 什么是 decltype 以及它是如何使用的?

c++ - 三元表达式中的逗号混淆

c++ - 编译lua代码,存储字节码然后加载并执行

c++ - vector 的 std::remove 和删除之间的区别?

c++ - "&s[0]"是否指向 std::string 中的连续字符?

c++ - 析构函数可以是最终的吗?

c++ - 为什么 reinterpret_cast 不能将 int 转换为 int?

c++ - 与 win32 CRITICAL_SECTION 相比的 std::mutex 性能

c++ - auto 和 decltype 的关系

c++ - 如何使用 C++ 模板减少编译时间