CPP Setup

Install Chocolatey

https://docs.chocolatey.org/en-us/choco/setup

Open new powershell.

  • Confirm choco command works.

Install CMake and Make using Chocolatey

https://community.chocolatey.org/packages/cmake https://community.chocolatey.org/packages/make

Open powershell as administrator and run the following:

Install cmake and add to path:

choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
choco install make

Close and reopen powershell.

  • Confirm cmake command works.
  • Confirm make command works.

Install vcpkg for installing libraries (Recommended)

https://vcpkg.io/en/getting-started.html

C:/cppdev is our chosen install directory for vcpkg, create your own directory and update the below commands as necessary.

Open powershell as administrator and run the following:

1) Download vcpkg repository

cd C:/cppdev/
git clone https://github.com/Microsoft/vcpkg.git

2) Run vcpkg install scripts

./vcpkg/bootstrap-vcpkg.bat
cd vcpkg
./vcpkg integrate install

Further Information: https://vcpkg.readthedocs.io/en/latest/examples/installing-and-using-packages/




Installing Libraries

As an example for demonstration, we will be building a WebSocket client using ixwebsocket.

Install ixwebsocket

cd C:/cppdev/vcpkg
./vcpkg install ixwebsocket:x64-windows

Make sure to use <libname>:x64-windows for libs to generate dlls

Outputs:

# ixwebsocket provides CMake targets:
find_package(ixwebsocket CONFIG REQUIRED)
target_link_libraries(<executable_name> PRIVATE ixwebsocket::ixwebsocket)

Copy the above lines to CMakeLists.txt as required (ixwebsocket already present in the example CMakeLists.txt).




Build Project

1) Build

Set the toolchain path either (a) in CMakeLists.txt or (b) manually in the build command:

(a) In CMakeLists.txt

set(CMAKE_TOOLCHAIN_FILE "C:/cppdev/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")

Run the build command:

cmake -S . -B build

(b) Manually in the build command

Run the build command:

cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=C:\\cppdev\vcpkg\scripts\buildsystems\vcpkg.cmake

2) Compile and Run

PowerShell (use ;), CMD / Bash (use &&)

cmake --build build ; ./build/Debug/<executable_name>

Run this every time you make a change to be recompile.




Example Server for Testing

websocat wss://prod-pusher.backend-capital.com/app/app_key?protocol=7&client=js&version=4.2.2&flash=true

Paste the following in the running shell:

{"event":"pusher:subscribe","data":{"channel":"27045129890124996"}}