C and C++ Driver for Debian & Ubuntu users

The MongoDB C++ Driver was recently accepted into the Debian experimental distribution (package page, announcement). The experimental distribution was chosen because the C++ Driver Team has not yet set a stable ABI for the C++ Driver; packages do not automatically migrate out of the experimental distribution, which ensures that they do not become part of a stable Debian release. For the same reasons stated above, we do not intend to request a sync of the package to Ubuntu until after a stable ABI has been established and the package is ready for the Debian unstable distribution.

Debian users wishing to make use of the MongoDB C++ Driver packages from the experimental distribution can follow the instructions from the Debian Wiki for installing experimental packages. Users of Debian stable or testing and users of Ubuntu can follow the instructions detailed below in this post to build and install the packages locally.

(Note: the following commands were executed on an Ubuntu 18.04 EC2 instance)

C Driver

  1. If your distribution has an old C Driver package, you will need to build that locally first (see what C Driver version is needed for a given C++ Driver you want to use here). If your distribution has a recent C Driver package (e.g., if you are using Debian unstable or testing), then you can simply install the necessary development package:

ubuntu@ip-10-122-3-175:~$ sudo apt-get install -y libmongoc-dev

  1. Ubuntu 18.04 has an old C Driver:

    ubuntu@ip-10-122-3-175:~$ apt-cache policy libmongoc-1.0-0
    libmongoc-1.0-0:
    Installed: (none)
    Candidate: 1.9.2+dfsg-1build1
    Version table:
    1.9.2+dfsg-1build1 500
    500 Index of /ubuntu bionic/universe amd64 Packages

  2. Install the build dependencies of the C Driver:

ubuntu@ip-10-122-3-175:~$ sudo apt-get install -y build-essential devscripts debian-keyring fakeroot debhelper cmake libssl-dev pkg-config python3-sphinx zlib1g-dev libicu-dev libsasl2-dev libsnappy-dev libzstd-dev

  1. Download the C Driver Debian source package:

ubuntu@ip-10-122-3-175:~$ dget httphttp://snapshot.debian.org/archive/debian-debug/20191108T152030Z/pool/main/m/mongo-c-driver/mongo-c-driver_1.15.2-1.dsc

(Note: You can check the “Versions” section of the mongo-c-driver Debian Package Tracking System status page to find the link to the latest available version. Additional intermediate versions of the C Driver may be available from the Debian Snapshots repository. You should also consult the MongoDB C++ Driver installation guide for information on C Driver version requirements and compatibility with C++ Driver versions.)

  1. Change into the unpacked directory:

ubuntu@ip-10-122-3-175:~$ cd mongo-c-driver-1.15.2/

  1. Depending on the version of the C Driver you are building and the jinja package available on your system, you may need to disable the documentation component of the build. For C Driver 1.17.0 and newer, this can be done like this:

ubuntu@ip-10-122-3-175:~$ export DEB_BUILD_OPTIONS="nodoc"

For earlier versions, you will need to edit the debian/rules file to make the following change:

--- a/debian/rules
+++ b/debian/rules
@@ -26,8 +26,8 @@ override_dh_auto_configure:
        -DBUILD_VERSION=$(DEB_VERSION_UPSTREAM) \
        -DENABLE_MONGOC=ON \
        -DENABLE_BSON=ON \
-       -DENABLE_MAN_PAGES=ON \
-       -DENABLE_HTML_DOCS=ON \
+       -DENABLE_MAN_PAGES=OFF \
+       -DENABLE_HTML_DOCS=OFF \
        -DENABLE_MAINTAINER_FLAGS=ON \
        -DENABLE_TESTS=OFF \
        -DENABLE_ZLIB=SYSTEM
  1. Build the packages:

ubuntu@ip-10-122-3-175:~/mongo-c-driver-1.15.2$ fakeroot dpkg-buildpackage --no-sign

  1. Install the development and runtime packages:

    ubuntu@ip-10-122-3-175:~/mongo-c-driver-1.15.2$ cd …
    ubuntu@ip-10-122-3-175:~$ sudo apt-get install -y ./libbson-1.0-0_1.15.2-1_amd64.deb ./libbson-dev_1.15.2-1_amd64.deb ./libmongoc-1.0-0_1.15.2-1_amd64.deb ./libmongoc-dev_1.15.2-1_amd64.deb

C++ Driver

  1. Once your system has a suitable C Driver package installed on it, then you can prepare to build the C++ Driver Debian source package. Begin by installing the build dependencies:

ubuntu@ip-10-122-3-175:~$ sudo apt-get install -y build-essential devscripts debian-keyring fakeroot debhelper cmake libboost-dev libsasl2-dev libicu-dev libzstd-dev doxygen

  1. Download the latest C++ Driver Debian source package:

ubuntu@ip-10-122-3-175:~$ dget http://deb.debian.org/debian/pool/main/m/mongo-cxx-driver/mongo-cxx-driver_3.4.1-1.dsc

(Note: You can check the “Versions” section of the mongo-cxx-driver Debian Package Tracking System status page to find the link to the latest available version.)

  1. Change into the unpacked directory:

ubuntu@ip-10-122-3-175:~$ cd mongo-cxx-driver-3.4.1/

  1. Build the packages:

ubuntu@ip-10-122-3-175:~/mongo-cxx-driver-3.4.1$ fakeroot dpkg-buildpackage --no-sign

  1. Install the resulting packages:

    ubuntu@ip-10-122-3-175:~/mongo-cxx-driver-3.4.1$ cd …
    ubuntu@ip-10-122-3-175:~$ sudo apt-get install -y ./libbsoncxx-dev_3.4.1-1_amd64.deb ./libbsoncxx-noabi_3.4.1-1_amd64.deb ./libmongocxx-dev_3.4.1-1_amd64.deb ./libmongocxx-noabi_3.4.1-1_amd64.deb

(Note: If you do not intend to compile against the C++ Driver, you can leave off the -dev packages.)

2 Likes