gpt4 book ai didi

c++ - MacOS Sierra - cmake 因 qt5 而失败

转载 作者:太空狗 更新时间:2023-10-29 20:10:25 24 4
gpt4 key购买 nike

我正在尝试使用 cmake 构建 cpp/qt5 项目,但编译返回有关 QT5 的错误。

我用 Homebrew 安装了 QT5,

当我这样做时:

brew --prefix qt5

我明白了

 /usr/local/Cellar/qt5/5.6.0

所以我在项目的 build 文件夹中,我这样做:

cmake .. -DCMAKE_PREFIX_PATH=$(brew --prefix qt5) -G Xcode -DBUILD_TESTS=ON -DBUILD_TESTS_COVERAGE=off

给我返回这个错误:

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

CMakelist.txt 中的错误行:

    ## QT5 ##

find_package(Qt5 COMPONENTS Core Gui Widgets Concurrent Qml Quick REQUIRED)

set_target_properties(${BIN_NAME} PROPERTIES AUTOMOC ON)
set_target_properties(${BIN_NAME} PROPERTIES AUTOUIC ON)
target_link_libraries(${BIN_NAME} PUBLIC Qt5::Core PUBLIC Qt5::Widgets PUBLIC Qt5::Gui PUBLIC Qt5::Qml PUBLIC Qt5::Quick PUBLIC Qt5::Concurrent)

#########

我还尝试在命令中添加 -DQt5_DIR=$(brew --prefix qt5),结果相同。


有什么想法吗?谢谢

最佳答案

尝试:

-DQt5_DIR=$(brew --prefix qt5)/lib/cmake/Qt5

请注意,您可以在使用set_target_properties 时指定多个属性,并在使用target_link_libraries 时为多个值指定PUBLIC 范围:

set_target_properties(${BIN_NAME}
PROPERTIES
AUTOMOC ON
AUTOUIC ON
)
target_link_libraries(${BIN_NAME}
PUBLIC
Qt5::Core
Qt5::Widgets
Qt5::Gui
Qt5::Qml
Qt5::Quick
Qt5::Concurrent
)

关于c++ - MacOS Sierra - cmake 因 qt5 而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40081327/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com