This section takes Linux as an example to introduce the installation process. Other systems are similar;

System Requirements

  • The Linux kernel should be not lower than 2.6.9, 64-bit version;
  • The gcc version is not less than 5.4.0;
  • Use cmake as the build tool, and the cmake version should be not less than 3.5;
  • Use git as the version management tool;

Library Dependencies

  • trantor, a non-blocking I/O C++ network library, also developed by the author of Drogon, has been used as a git repository submodule, no need to install in advance;
  • jsoncpp, JSON’s c++ library, the version should be no less than 1.7;
  • libuuid, generating c library of uuid;
  • zlib, used to support compressed transmission;
  • OpenSSL, not mandatory, if the OpenSSL library is installed, drogon will support HTTPS as well, otherwise drogon only supports HTTP.
  • c-ares, not mandatory, if the c-ares library is installed,drogon will be more efficient with DNS;
  • libbrotli, not mandatory, if the libbrotli library is installed, drogon will support brotli compression when sending HTTP responses;
  • boost, the version should be no less than 1.61, is required only if the C++ compiler does not support C++ 17 and if the STL doesn’t fully support std::filesystem.
  • the client development libraries of postgreSQL, mariadb and sqlite3, not mandatory, if one or more of them is installed, drogon will support access to the according database.
  • gtest, not mandatory, if the gtest library is installed, the unit tests can be compiled.

System Preparation Examples

Ubuntu 18.04

Environment
  1. sudo apt install git
  2. sudo apt install gcc
  3. sudo apt install g++
  4. sudo apt install cmake
jsoncpp
  1. sudo apt install libjsoncpp-dev
uuid
  1. sudo apt install uuid-dev
OpenSSL
  1. sudo apt install openssl
  2. sudo apt install libssl-dev
zlib
  1. sudo apt install zlib1g-dev

CentOS 7.5

Environment
  1. yum install git
  2. yum install gcc
  3. yum install gcc-c++

The default installed cmake version is too low, use source installation

  1. git clone https://github.com/Kitware/CMake
  2. cd CMake/
  3. ./bootstrap && make && make install

Upgrade gcc

  1. yum install centos-release-scl
  2. yum install devtoolset-8
  3. scl enable devtoolset-8 bash

Note: Command scl enable devtoolset-8 bash only activate the new gcc temporarily until the session is end. If you want to always use the new gcc, you could run command echo "scl enable devtoolset-8 bash" >> ~/.bash_profile, system will automatically activate the new gcc after restarting.

jsoncpp
  1. git clone https://github.com/open-source-parsers/jsoncpp
  2. cd jsoncpp/
  3. mkdir build
  4. cd build
  5. cmake ..
  6. make && make install
uuid
  1. yum install libuuid-devel
OpenSSL
  1. yum install openssl-devel
zlib
  1. yum install zlib-devel

MacOS 12.2

Environment

All the essentials are inherent in MacOS, you only need to upgrade it.

upgrade gcc
  1. brew upgrade
jsoncpp
  1. brew install jsoncpp
uuid
  1. brew install ossp-uuid
OpenSSL
  1. brew install openssl
zlib
  1. brew install zlib

Windows

Environment

Install Visual Studio 2019 professional 2019, at least included these options:

  • MSVC C++ building tools
  • Windows 10 SDK
  • C++ CMake tools for windows
  • Test adaptor for Google Test
Package Manager

If python is installed on system, you could install conan package manager via pip, of course you can download the installation file from connan official website to install it also.

  1. pip install conan

conan package manager could provide all dependencies that Drogon projector needs。

Database Environment

Note: These libraries below are not mandatory. You could choose to install one or more database according to your actual needs.

Note: If you want to develop your webapp with database, please install the database develop environment first, then install drogon, otherwise you will encounter a NO DATABASE FOUND issue.

PostgreSQL

PostgreSQL’s native C library libpq needs to be installed. The installation is as follows:

  • ubuntu 16: sudo apt-get install postgresql-server-dev-all
  • ubuntu 18: sudo apt-get install postgresql-all
  • centOS 7: yum install postgresql-devel
  • MacOS: brew install postgresql

MySQL

MySQL’s native library does not support asynchronous read and write. Fortunately, MySQL also has a version of MariaDB maintained by the original developer community. This version is compatible with MySQL, and its development library supports asynchronous read and write. Therefore, Drogon uses the MariaDB development library to provide the right MySQL support, as a best practice,your operating system shouldn’t install both Mysql and MariaDB at the same time.

MariaDB installation is as follows:

  • ubuntu: sudo apt install libmariadbclient-dev
  • centOS 7: yum install mariadb-devel
  • MacOS: brew install mariadb

Sqlite3

  • ubuntu: sudo apt-get install libsqlite3-dev
  • centOS: yum install sqlite-devel
  • MacOS: brew install sqlite3

Redis

  • ubuntu: sudo apt-get install libhiredis-dev

Note: Some of the above commands only install the development library. If you want to install a server also, please use Google search yourself.

Drogon Installation

Assuming that the above environment and library dependencies are all ready, the installation process is very simple;

Install by source in Linux

  1. cd $WORK_PATH
  2. git clone https://github.com/drogonframework/drogon
  3. cd drogon
  4. git submodule update --init
  5. mkdir build
  6. cd build
  7. cmake ..
  8. make && sudo make install

The default is to compile the debug version. If you want to compile the release version, the cmake command should take the following parameters:

  1. cmake -DCMAKE_BUILD_TYPE=Release ..

After the installation is complete, the following files will be installed in the system(One can change the installation location with the CMAKE_INSTALL_PREFIX option):

  • The header file of drogon is installed into /usr/local/include/drogon;
  • The drogon library file libdrogon.a is installed into /usr/local/lib;
  • Drogon’s command line tool drogon_ctl is installed into /usr/local/bin;
  • The trantor header file is installed into /usr/local/include/trantor;
  • The trantor library file libtrantor.a is installed into /usr/local/lib;

Install by source in Windows

After installed conan package manager, run command in PowerShell for Visual studio as bellow:

  1. cd $WORK_PATH
  2. git clone https://github.com/drogonframework/drogon
  3. cd drogon
  4. git submodule update --init
  5. mkdir build
  6. cd build
  7. conan install .. -s compiler="Visual Studio" -s compiler.version=16 -s build_type=Debug -g cmake_paths
  8. cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=D:/ -DCMAKE_TOOLCHAIN_FILE=./conan_paths.cmake
  9. cmake --build . --parallel --target install

Note: Must keep build type same in conan and cmake.

After the installation is complete, the following files will be installed in the system(One can change the installation location with the CMAKE_INSTALL_PREFIX option):

  • The header file of drogon is installed into D:/include/drogon;
  • The drogon library file drogon.dll is installed into D:/bin;
  • Drogon’s command line tool drogon_ctl.exe is installed into D:/bin;
  • The trantor header file is installed into D:/include/trantor;
  • The trantor library file trantor.dll is installed into D:/lib;

Use vcpkg

The easiest way to install drogon on windows is to use vcpkg

  1. vcpkg.exe install drogon

Or

  1. vcpkg.exe install drogon:x64-windows

if you haven’t install vcpkg:

  1. Lazzy to read

  2. Assuming that you don’t have cmake.exe, make.exe/nmake.exe/ninja.exe and vcpkg.exe

  3. Make it sure you’re already install git for windows too

  4. First, go to where you want to install vcpkg.

    • In this case, we’re gonna use C:/dev directory.
    • If you don’t have that directory yet, open your powershell as administrator:
      • type and enter:
        • cd c:/
        • mkdir dev;cd dev; mean you will create dev and go to dev directory
        • git clone https://github.com/microsoft/vcpkg or git clone git@github.com:microsoft/vcpkg.git
        • cd vcpkg
        • ./bootstrap-vcpkg.bat this will install vcpkg.exe note: to update your vcpkg, you just need to type git pull to make it sure that vcpkg directory always able to access:
          • add C:/dev/vpckg to your windows environment variables.
            • restart/re-open your powershell
  5. Now check if vcpkg already installed properly, just type vcpkg or vcpkg.exe

  6. To install drogon framework. Type:

    • 32-Bit: vcpkg install drogon
    • 64-Bit: vcpkg install drogon:x64-windows
    • extra : vcpkg install jsoncpp:x64-windows zlib::x64-windows openssl::x64-windows sqlite3:x64-windows libpq:x64-windows libpqxx:x64-windows drogon[core,ctl,sqlite3,postgres,orm]:x64-windows
    • wait till all dependencies are installed.
    • note:
      • if there’s any package is/are uninstalled and you got error, just install that package. e.g.:
        • zlib : vcpkg install zlib or vcpkg install zlib:x64-windows for 64-Bit
      • to check what already installed:
        • vcpkg list
      • use vcpkg search for what available.
  7. To add drogon_ctl command and dependencies, you need to add some variables. By following this guide, you just need to add:

    1. C:\dev\vcpkg\installed\x64-windows\tools\drogon
    1. C:\dev\vcpkg\installed\x64-windows\bin
    1. C:\dev\vcpkg\installed\x64-windows\lib
    1. C:\dev\vcpkg\installed\x64-windows\include
    1. C:\dev\vcpkg\installed\x64-windows\share
    1. C:\dev\vcpkg\installed\x64-windows\debug\bin
    1. C:\dev\vcpkg\installed\x64-windows\debug\lib

    to your windows environment variables.

  8. reload/re-open your powershell, then type:

    • drogon_ctl or drogon_ctl.exe
    • press enter
    • if:
      1. usage: drogon_ctl [-v | --version] [-h | --help] <command> [<args>]
      2. commands list:
      3. create create some source files(Use 'drogon_ctl help create' for more information)
      4. help display this message
      5. press Do stress testing(Use 'drogon_ctl help press' for more information)
      6. version display version of this tool
      showed up, you are good to go.
  9. Note:

    • you need to be familiar with building cpp libraries by using:

    • consider use make.exe/nmake.exe/ninja.exe as cmake generator since configuration and build behaviour is same as make linux, if some devs using Linux/Windows and you are planning to deploy on Linux environment, it’s less prone error when switching operating-system.


Use Docker Image

We also provide a pre-build docker image on the docker hub. All dependencies of Drogon and Drogon itself are already installed in the docker environment, where users can build Drogon-based applications directly.

Use Nix Package

There is a Nix package for Drogon which was released in version 21.11.

You can use the package by adding the following shell.nix to your project root:

  1. { pkgs ? import <nixpkgs> {} }:
  2. pkgs.mkShell {
  3. nativeBuildInputs = with pkgs; [
  4. cmake
  5. ];
  6. buildInputs = with pkgs; [
  7. drogon
  8. ];
  9. }

Enter the shell by running nix-shell. This will install Drogon and enter you into an environment with all its dependencies.

The Nix package has a few options which you can configure according to your needs:

option default value
sqliteSupport true
postgresSupport false
redisSupport false
mysqlSupport false

Here is an example of how you can change their values:

  1. buildInputs = with pkgs; [
  2. (drogon.override {
  3. sqliteSupport = false;
  4. })
  5. ];

if you haven’t installed Nix: You can follow the instructions on the NixOS website.

Include drogon source code locally

Of course, you can also include the drogon source in your project. Suppose you put the drogon under the third_party of your project directory (don’t forget to update submodule in the drogon source directory). Then, you only need to add the following two lines to your project’s cmake file:

  1. add_subdirectory(third_party/drogon)
  2. target_link_libraries(${PROJECT_NAME} PRIVATE drogon)

Use CPM.cmake

You can use CPM.cmake to include the drogon source code:

  1. include(cmake/CPM.cmake)
  2. CPMAddPackage(
  3. NAME drogon
  4. VERSION 1.7.5
  5. GITHUB_REPOSITORY drogonframework/drogon
  6. GIT_TAG v1.7.5
  7. )
  8. target_link_libraries(${PROJECT_NAME} PRIVATE drogon)

03 Quick Start