根据https://blog.kitware.com/cmake-finding-qt5-the-right-way/,方法find_package(Qt5 COMPONENTS Core Qml Quick Svg Qt5WebSockets REQUIRED)
允许我加载许多QT5软件包,而只能通过设置Qt5_DIR
变量来设置QT根一次。我正在尝试使用此技术来编译下面列出的最小CMake项目。 您可以看到未找到WebSockets。有什么问题吗?
PS:我的主目录/home/lz/Qt5.11.2
确实安装了Qt安装程序为我安装的新Qt安装,并且确实具有libwebsockets和websocket包含文件。
我的CMakeLists.txt:
find_package(Qt5 COMPONENTS Core Qml Quick Svg Qt5WebSockets REQUIRED)
我如何运行它:
cmake -DQt5_DIR=/home/lz/Qt5.11.2 .
-- The C compiler identification is GNU 7.2.0
-- The CXX compiler identification is GNU 7.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /usr/lib/x86_64-linux-gnu/cmake/Qt5/Qt5Config.cmake:28 (find_package):
Could not find a package configuration file provided by "Qt5Qt5WebSockets"
with any of the following names:
Qt5Qt5WebSocketsConfig.cmake
qt5qt5websockets-config.cmake
Add the installation prefix of "Qt5Qt5WebSockets" to CMAKE_PREFIX_PATH or
set "Qt5Qt5WebSockets_DIR" to a directory containing one of the above
files. If "Qt5Qt5WebSockets" provides a separate development package or
SDK, be sure it has been installed.
Call Stack (most recent call first):
CMakeLists.txt:1 (find_package)
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 3.9)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring incomplete, errors occurred!
See also "/home/lz/c/CMakeFiles/CMakeOutput.log".
PS:没有WebSockets的情况下,可以进行“编译”,因此WebSockets是唯一找不到的模块
更新:
在获得以下帮助之后,我仍然遇到与WebSocket相关的错误:
/home/lz/orwell/react-native-desktop-orwell/ReactQt/runtime/src/websocketmodule.cpp:12:10: fatal error: QWebSocket: No such file or directory
#include <QWebSocket>
现在,我可以成功使用我的QT,如您在详细输出中所见:
[ 50%] Building CXX object CMakeFiles/m.dir/main.o
/usr/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -isystem /home/lz/Qt5.11.2/5.11.2/gcc_64/include -isystem /home/lz/Qt5.11.2/5.11.2/gcc_64/include/QtWidgets -isystem /home/lz/Qt5.11.2/5.11.2/gcc_64/include/QtGui -isystem /home/lz/Qt5.11.2/5.11.2/gcc_64/include/QtCore -isystem /home/lz/Qt5.11.2/5.11.2/gcc_64/./mkspecs/linux-g++ -fPIC -std=gnu++11 -o CMakeFiles/m.dir/main.o -c /home/lz/c/main.cpp
/home/lz/c/main.cpp:1:10: fatal error: QWebSocket: No such file or directory
#include <QWebSocket>
^~~~~~~~~~~~
compilation terminated.
答案 0 :(得分:1)
将CMakeLists.txt中的行更改为
find_package(Qt5 COMPONENTS Core Qml Quick Svg WebSockets REQUIRED)
您无需使用此语法在组件名称上添加“ Qt5”前缀。