Skip to content

Building and installation#

This library uses C++ 17, supports Linux (GCC) and Windows (Visual Studio 2019/2022) compilers.

This library has dependencies:
- curl - for HTTP requests.
- nlohmann-json - to work with JSON.
- websocketpp - for websocket requests.

Steps for building and installing the library:
1. Installing dependencies
2. Configuration
3. Building
4. Importing the library to a project
5. Working with examples

1. Installing dependencies#

Clone the repository

git clone https://github.com/green-api/whatsapp-api-client-cpp.git

Windows#

Installing dependencies using vcpkg package manager:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
bootstrap-vcpkg.bat
vcpkg install curl
vcpkg install nlohmann-json
# vcpkg install websocketpp (optional)
vcpkg integrate install

Windows x64#

Most Windows machines now have x64 version, but vcpkg uses x86 packages by default.

vcpkg install nlohmann-json:x64-windows
vcpkg install curl:x64-windows

To execute commands in PowerShell it is required to change commands to .\vcpkg

After building bootstrap-vcpkg.bat it is required to add vcpkg.exe into the PATH variables of your system PATH\vcpkg\installed\x64-windows\bin.

Linux#

Installing dependencies using vcpkg package manager:

  • Dependencies
  • curl
  • nlohmann-json
  • websocketpp (optional)

You can install dependencies with ready-made install.sh scenario (sudo sh install.sh) or manually:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg/vcpkg install curl
./vcpkg/vcpkg install nlohmann-json
# ./vcpkg install websocketpp (optional)
./vcpkg/vcpkg integrate install

2. Configuration#

The library has a configuration file - config.hpp

In the configuration file you can specify required building parameters:

// Default parameters are specified below
#define CURL_LOG false          // true/false logging level of the installed cURL library 
#define GA_CURLOPT_TIMEOUT 60L  // General waiting time from the server
#define GA_CURLOPT_CONNECTTIMEOUT 15L  // Connection time with the server

#define LOG_FILE false          // Recording logs in the log file
#define LOG_CONSOLE false       // log output to the console (errors are always output to the console)

After configuration it is required to build the library with the new parameters

3. Building#

Windows#

To build the library you will need:

Building is done by using the build.bat scenario or manually by using CMake (compiling Debug version of the library):

mkdir build
cd build
cmake ..
cd ../
cmake --build build

Most likely you will have to specify direct paths to the used libraries, uncomment the lines in CMakeList.txt

Linux#

You can build the library with ready-made build.sh scenario (sudo sh build.sh) or manually:

mkdir build
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake
cmake --build build/

You can change vcpkg catalogue by specifying relative or absolute path.

You might need to install additional packages to build the library:

sudo apt-get update
sudo apt-get install cmake
sudo apt-get install g++
sudo apt-get install pkg-config
sudo apt-get install libcurl4-openssl-dev
sudo apt install build-essential

4. Importing the library to a project#

Windows#

You can import the library in Visual Studio by adding the whatsapp-api-client-cpp.lib file in the project dependencies:

  1. Properties -> Configuration properties -> C/C++ -> General -> Additional Include Directories (PATH/whatsapp-api-client-cpp/include)
  2. Properties -> Configuration properties -> Linker -> General -> Additional Library Directories (PATH/build/)
  3. Properties -> Configuration properties -> Linker -> Inpit -> Additional Dependencies (whatsapp-api-client-cpp.lib)

Carefully choose your configuration type and install required library version (debug and release)

5. Working with examples#

All examples are put in the examples, every file has examples of all the methods with all the supported parameters. To run a particular example it is required to copy a code section into your main.cpp file and use your values in the parameters.