从这里:https://stackoverflow.com/a/28327499/462608
我试过了:
cmake_minimum_required(VERSION 2.8.12)
project(qtquick_hello_cmake)
set(CMAKE_PREFIX_PATH "/opt/Qt5.9.1/5.9.1/")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5 COMPONENTS Quick Core REQUIRED)
qt5_add_resources(RESOURCES qml.qrc)
add_executable(${PROJECT_NAME} "main.cpp" "qml.qrc")
qt5_use_modules(${PROJECT_NAME} Quick Core)
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Quick)
这里是cmake .
的输出
:~/junk/qtquick_hello_cmake$ cmake .
CMake Error at CMakeLists.txt:11 (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.
-- Configuring incomplete, errors occurred!
See also "/home/.../junk/qtquick_hello_cmake/CMakeFiles/CMakeOutput.log".
这是为了证明/opt/Qt5.9.1/
确实存在
:~/junk/qtquick_hello_cmake$ cd /opt/Qt5.9.1/5.9.1/
:/opt/Qt5.9.1/5.9.1$ ls
android_armv7 android_x86 gcc_64 Src
这里我使用-DCMAKE选项运行cmake,但输出仍然相同:
:~/junk/qtquick_hello_cmake$ cmake -DCMAKE_PREFIX_PATH=/opt/Qt5.9.1/5.9.1/ -DWITH_QT5=1 .
CMake Error at CMakeLists.txt:11 (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.
-- Configuring incomplete, errors occurred!
See also "/home/.../junk/qtquick_hello_cmake/CMakeFiles/CMakeOutput.log".
目录内容:
:~/junk/qtquick_hello_cmake$ ls
CMakeCache.txt CMakeFiles CMakeLists.txt main.cpp main.qml qml.qrc
7条答案
按热度按时间sr4lhrrt1#
我安装了以下缺少的软件包:
现在不需要附加任何类型的前缀:
CMakeList:
新增输出:
错误现在消失了。
感谢:
https://answers.ros.org/question/236324/could-not-find-a-package-configuration-file-provided-by-qt5widgets/
https://askubuntu.com/questions/508503/whats-the-development-package-for-qt5-in-14-04
qaxu7uf22#
对于macOS,在终端中导出以下变量。
可能有另一个版本,请检查您拥有的版本,并相应地更改最后一个路径组件。
发出构建重新配置
5tmbdcev3#
我最近遇到了这个问题,我通过将此添加到产生此错误的任何CMakeLists.txt来解决此问题:
bpsygsoo4#
另一种解决方案,例如,如果您在主目录中手动安装了Qt(而不是使用系统目录),则可以在命令行中指定您想要使用的版本。示例:
请注意指定您使用的版本+目标系统。然后,Qt会在子目录中找到合适的配置文件。
t9eec4r05#
CMake有关
find_package
失败的错误消息并设置 CMAKE_PREFIX_PATH 变量在CMAKE_PREFIX_PATH中添加安装前缀“Qt5”
有点误导人它只谈到了“安装前缀”,但这个安装仍然要求包含
Qt5Config.cmake
或qt5-config.cmake
文件,以便被find_package
发现。但是信息
如果“Qt5”提供了单独的开发包或SDK,请确保已安装。
很清楚:
需要安装一个包含所需配置文件的开发包。
以上所有内容仅适用于
find_package
的 CONFIG 模式,当CMake和使用此命令的CMake项目都没有提供“Find”脚本时。iovurdzv6#
几年后,我在使用新的Android NDK工具链时遇到了类似的问题。这里提供的解决办法是不够的。我发现了一个新的方法,并在这里发布了以下内容:
这将打印出CMake找到包文件的查找过程。
jxct1oxe7#
对于MacOS,我使用CMake应用程序通过将“Where is source code”设置为我的cpp文件的目录,并将“Where to build the binaries”设置为build文件夹来澄清Qt5_DIR。然后,输入“/usr/local/Cellar/qt@5/5.15.8_3/lib/cmake/Qt”作为实际的Qt5_DIR值。随着新更新的发布,目录可能会随着时间的推移而更改,因此您每次都必须手动查找Qt5Config.cmake文件以更新Qt5_DIR