Search code examples
ubuntunetwork-programminginstallationuwebsockets

Correct way to install and run uWebSockets in C++


What is the recommended way to install the library uWebSockets (https://github.com/uNetworking/uWebSockets) and be able to compile the accompanying examples ? I have tried the solution provided here: How to install uWebSockets? with no success: I ran the file install-linux.sh (see link above), the installation worked (no error message). Then, when I try to compile the example HelloWorld.cpp (see https://github.com/uNetworking/uWebSockets/blob/master/examples/HelloWorld.cpp), with:

g++ -std=c++17 HelloWorld.cpp

I get:

HelloWorld.cpp:1:10: fatal error: App.h: no such file or directory

So, my questions are:

  1. How do I correctly install the library,
  2. What exact command should I use to compile the examples ?

I am using g++ with Ubuntu 20.04 LTS.


Solution

  • I did this:

    git clone --recurse-submodules git@github.com:uNetworking/uWebSockets.git
    cd uWebSockets
    WITH_OPENSSL=1 make examples
    

    It built all examples, including HelloWorld, clean.

    If you want to use WolfSSL instead, then make the examples using this instead:

    WITH_WOLFSSL=1 WITH_LIBUV=1 make examples
    

    If you want to install the uWebSockets header files together with other libraries you've downloaded:

    make DESTDIR=$HOME/.local prefix= install
    

    The uSocket sub module doesn't seem to get installed - or have a proper installation procedure so you'll have to do some digging to find out which headers are needed (if any). Building the examples produced some uSocket libraries though:

    ./uSockets/boringssl/util/ar/testdata/linux/libsample.a
    ./uSockets/boringssl/util/ar/testdata/mac/libsample.a
    ./uSockets/uSockets.a
    

    These should probably be copied to where you store other third party libraries ($HOME/.local/lib perhaps). I assume you need to link your uWebSockets apps with uSockets.a. You can probably figure out how by looking at the examples.