1

uWebSockets https://github.com/uNetworking/uWebSockets

How to use this from Visual Studio C++ ? I wish to implement a simple websocket server. I don't want to use Makefile, wish to use normal visual studio project build.

Phil
  • 46,436
  • 33
  • 110
  • 175
  • You should ask in the github repo, but it looks the guys who write that prefer to stick to the "1970s Makefile because it does the job and has done for 5 decades." https://github.com/uNetworking/uWebSockets/issues/1043 otherwise https://stackoverflow.com/questions/314553/how-to-use-makefiles-in-visual-studio – Simon Mourier May 16 '20 at 08:03
  • Sadly... well, it "does the job" but I'm in a normal visual studio C++ project and want to use it... – Phil May 16 '20 at 08:05

2 Answers2

3

This is how to use uWebsockets from Visual C++ IDE project, step by step:

  1. Install Vcpkg https://github.com/microsoft/vcpkg
    then command line the following
  2. set VCPKG_DEFAULT_TRIPLET=x64-windows
  3. vcpkg install uwebsockets

At this point there is then a folder vcpkg\installed\x64-windows which contains the header files and library files and dlls (if you need the dlls).

In your Visual C++ project properties set the include directory and lib directory in the VC Directories.

Then #include <uwebsockets/App.h> and paste code from uwebsockets.

ariestav
  • 2,799
  • 4
  • 28
  • 56
Phil
  • 46,436
  • 33
  • 110
  • 175
  • This seems to work, and code does in fact build. I'm trying to integrate uWebSockets into some C++ code that ends up being built as a .dll for a host application. The uWebSockets code seems to build fine in Visual Studio 2022, but when it loads into the host app during runtime and error is reported that the built dll does not work. – ariestav Jul 04 '22 at 22:43
  • Just wanted to update on my previous comment: I had to place the .dll files that were built in the same directory as the .exe that loads the .dlls. The error goes away after that. – ariestav Sep 09 '22 at 15:00
  • this actually build the debug configs. How do we build the release configs? – ariestav Sep 09 '22 at 20:46
  • ah, nevermind. release builds are simply placed into the packages bin folder, but the debug builds are placed in the debug\bin folder. there is no release\bin folder. – ariestav Sep 10 '22 at 01:00
1
  1. If visual studio gives 500+ errors when #include <uwebsockets/App.h>, then connect c++ 20.
  2. If you are building an exe file, then write it at the beginning of the code. #pragma comment(lib, "uSockets.lib") #pragma comment(lib, "uv.lib") #pragma comment(lib, "zlib.lib")
  3. Good luck!
Дима
  • 11
  • 2