CMake find_package 找不到 WebSockets

CMake find_package can't find WebSockets

本文关键字:找不到 WebSockets package find CMake      更新时间:2023-10-16

根据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 cmake'Commiles'就可以了,因此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.

将您的cmakelists.txt中的行更改为

find_package(Qt5 COMPONENTS Core Qml Quick Svg WebSockets REQUIRED)

您不需要使用此语法将" QT5"前缀添加到组件的名称。

对我安装libqt5websockets5-dev

sudo apt install libqt5websockets5-dev