C++ 将“Qt5Widgets”的安装前缀添加到CMAKE_PREFIX_PATH

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22215900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:59:59  来源:igfitidea点击:

Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH

c++qtcmake

提问by user3386675

I don't know a lot about cmake, I'm trying to build a client using cmake and Qt. Getting the following error:

我对 cmake 了解不多,我正在尝试使用 cmake 和 Qt 构建客户端。得到以下错误:

CMake Error at alethzero/CMakeLists.txt:26 (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.

-- Configuring incomplete, errors occurred!

alethzero/CMakeLists.txt:26 (find_package) 中的 CMake 错误:通过在 CMAKE_MODULE_PATH 中不提供“FindQt5Widgets.cmake”,该项目
要求 CMake 找到
“Qt5Widgets”提供的包配置文件,但 CMake 没有找到。

找不到“Qt5Widgets”提供的具有以下任何名称的包配置文件:

Qt5WidgetsConfig.cmake
qt5widgets-config.cmake

将“Qt5Widgets”的安装前缀添加到 CMAKE_PREFIX_PATH 或将“Qt5Widgets_DIR”设置为包含上述文件之一的目录。如果“Qt5Widgets”提供单独的开发包或SDK,请确保已安装。

-- 配置不完整,出现错误!

As far as I understand, I need to add the QT path to CMake. How do I do it? I have Qt installed in /home/user/Programs. All the explanations I find are "just do this or that". I need the exact Terminal commands so I can just learn how to do it in the future.

据我了解,我需要将 QT 路径添加到 CMake。我该怎么做?我在 /home/user/Programs 中安装了 Qt。我找到的所有解释都是“做这个或那个”。我需要确切的终端命令,以便我将来可以学习如何执行此操作。

Thanks!

谢谢!

UPDATE: export CMAKE_PREFIX_PATH=/home/user/Programsdid not help me.

更新:export CMAKE_PREFIX_PATH=/home/user/Programs没有帮助我。

回答by steveire

This is documented:

这是记录在案的:

http://doc.qt.io/qt-5/cmake-manual.html

http://doc.qt.io/qt-5/cmake-manual.html

The easiest way to use CMake is to set the CMAKE_PREFIX_PATH 
environment variable to the install prefix of Qt 5

Do this

做这个

export CMAKE_PREFIX_PATH=/home/user/Programs/<other_stuff>

where references the compiler etc, so that this complete path is valid:

where 引用了编译器等,以便此完整路径有效:

/home/user/Programs/<other_stuff>/bin/qmake*

回答by lmiguelmh

Well, here you have a solution for Windows: How to find qt5 CMake module on windows

好吧,这里有一个适用于 Windows 的解决方案:How to find qt5 CMake module on windows

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

For your environment, I think you will have to change the path where Qt is located...

对于您的环境,我认为您将不得不更改 Qt 所在的路径...

Maybe this will help you:
https://github.com/Cockatrice/Cockatrice/issues/205

也许这会帮助你:https:
//github.com/Cockatrice/Cockatrice/issues/205

回答by Ebrahim Byagowi

I needed this on my macOS after Qt installation with brew install qt5:

安装 Qt 后,我​​需要在我的 macOS 上使用brew install qt5

export CMAKE_PREFIX_PATH=/usr/local/Cellar/qt5/5.7.0/

回答by ryancheung

For ubuntu: cmake -DCMAKE_PREFIX_PATH=/home/ryan/Qt/5.11.2/gcc_64 ..

对于 ubuntu: cmake -DCMAKE_PREFIX_PATH=/home/ryan/Qt/5.11.2/gcc_64 ..

/home/ryan/Qt/is the Qt installation root path

/home/ryan/Qt/是Qt安装根路径

回答by fometeo

at an Ubuntu 16.04.4 LTS desktop the solution was

在 Ubuntu 16.04.4 LTS 桌面上,解决方案是

cmake .. -DMAKE_PREFIX_PATH=/usr/include/x86_64-linux-gnu/qt5