How to install libwebsocket form git? (discussion with gemenie)

Installing libwebsockets (LWS) directly from GitHub uses standard CMake.

Step-by-Step Installation (Linux / macOS)

1. Install System Dependencies

LWS requires cmake, gcc/g++ (or clang), and SSL headers (OpenSSL/WolfSSL).

  • Ubuntu / Debian:

    Bash
    sudo apt update
    sudo apt install -y git cmake build-essential libssl-dev zlib1g-dev
    
  • Fedora / RHEL / CentOS:

    Bash
    sudo dnf install -y git cmake gcc gcc-c++ openssl-devel zlib-devel
    
  • macOS (Homebrew):

    Bash
    brew install git cmake openssl zlib
    

2. Clone the Official Repository

Clone the repository and check out a stable release tag (recommended over main for production reliability):

Bash
# Clone the repository
git clone https://github.com/warmcat/libwebsockets.git
cd libwebsockets

# (Optional) Checkout a stable release tag
git checkout v4.3-stable

3. Build and Install via CMake

LWS requires an out-of-source build directory:

Bash
# Create and enter build directory
mkdir build && cd build

# Configure build files
cmake .. \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_INSTALL_PREFIX=/usr/local \
  -DLWS_WITH_SSL=ON \
  -DLWS_WITH_HTTP2=ON

# Compile using all CPU cores
make -j$(nproc)

# Install system-wide
sudo make install

# Refresh shared library link cache (Linux)
sudo ldconfig

Key CMake Options (Customizing Your Build)

You can pass extra flags to cmake .. depending on your requirements:

FlagDefaultDescription
-DLWS_WITH_SSL=ONONEnables OpenSSL/TLS support.
-DLWS_WITH_HTTP2=ONONEnables HTTP/2 protocol support.
-DLWS_WITH_MINIMAL_EXAMPLES=ONOFFBuilds sample client/server code in the build folder.
-DLWS_MAX_SMP=81 / AutoSets maximum SMP thread count for multi-threaded service loops.
-DCMAKE_INSTALL_PREFIX=/usr/usr/localChanges the default installation target directory.

Verifying the Installation

To verify your installation, create a minimal C test file (test.c):

C
#include <libwebsockets.h>
#include <stdio.h>

int main() {
    printf("LWS Version: %s\n", lws_get_library_version());
    return 0;
}
Compile and run it:
Bash
gcc test.c -o test -lwebsockets
./test

No comments:

Post a Comment

If you have any doubts, please let me know.

Various types of salts effect on health (discussion with gemenie)

Is  rock salt or bitnoon helps in digestion or just a airuvedic nuska This is for informational purposes only. For medical advice or diagnos...