简体   繁体   English

使用 CMake 在 Windows 10 上构建 uWebSockets

[英]Build uWebSockets on Windows 10 with CMake

I want to use uWebSockets (UWS) in my C++ project to transfer images over the network.我想在我的 C++ 项目中使用uWebSockets (UWS) 通过网络传输图像。 The setup will be running on multiple operating systems, so the best way of creating the build files seemed like using CMake.该设置将在多个操作系统上运行,因此创建构建文件的最佳方式似乎是使用 CMake。

However, I am new to CMake and having a hard time building UWS.但是,我是 CMake 的新手,并且很难构建 UWS。 I don't understand how to start working with the official repository on Windows 10, so I found another repository that includes a CMakeFiles.txt file and some of the dependencies ( openssl, zlib, libuv , but it doesn't include uSockets for some reason).我不明白如何开始使用 Windows 10 上的官方存储库,所以我找到了另一个存储库,其中包含一个CMakeFiles.txt文件和一些依赖项( openssl、zlib、libuv ,但它不包括某些uSockets原因)。 The root CMakeFiles.txt includes:CMakeFiles.txt包括:

[...] 

find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)

find_path(LIBUV_INCLUDE_DIR uv.h)
find_library(LIBUV_LIBRARY NAMES uv uv1)

[...] 

It looks straightforward, but when I try to run mkdir build && cd build; cmake ..看起来很简单,但是当我尝试运行mkdir build && cd build; cmake .. mkdir build && cd build; cmake .. , it cannot find OpenSSL . mkdir build && cd build; cmake .. ,它找不到OpenSSL Here is the error message it spits out:这是它吐出的错误消息:

[...]
[cmake]   Could not find a package configuration file provided by "OpenSSL" with any
[cmake]   of the following names:
[cmake] 
[cmake]     OpenSSLConfig.cmake
[cmake]     openssl-config.cmake
[...]

The above error message suggests that I need to set up a config file for each of these libraries.上面的错误消息表明我需要为每个库设置一个配置文件。 Yet, if I understand the find_package docs correctly, the command itself searches the library in various locations under the root folder.然而,如果我正确理解find_package文档,命令本身会在根文件夹下的不同位置搜索库。 What kind of a folder structure does the find_package need in order to work? find_package需要什么样的文件夹结构才能工作?

More generally, am I wasting my time with this alternative repo?更一般地说,我是不是在用这个替代回购浪费我的时间? Is there a better way of using UWS with Windows 10?在 Windows 10 上使用 UWS 有没有更好的方法? The official repo has a question about how to use it on Windows but I don't understand how that's an answer to the question.官方 repo 有一个关于如何在 Windows 上使用它的问题,但我不明白这是如何回答这个问题的。 It only points to this page where it says any specific build systems will not officially be supported.它仅指向此页面,其中表示将不正式支持任何特定的构建系统。

Any help would be appreciated.任何帮助,将不胜感激。

Importing dependencies with add_subdirectory seems like a good way around this.使用add_subdirectory导入依赖项似乎是解决此问题的好方法。 When I ran cmake, I was receiving LNK2019 Error.当我运行 cmake 时,我收到 LNK2019 错误。 I realized the following code snippet I found online was causing the problem, and the system works when I delete it.我意识到我在网上找到的以下代码片段导致了问题,当我删除它时系统可以工作。

if(MSVC)
    set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:msvcrt.lib")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS")
endif()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM