Industry best practices and some regulations require the use of TLS 1.1
or newer. The MongoDB C Driver supports TLS 1.1 on Linux if OpenSSL is
at least version 1.0.1. On macOS and Windows, the C Driver uses native
TLS implementations that support TLS 1.1.

Step 2: Choose a C++17 polyfill

The mongocxx driver uses the C++17 features std::optional and
std::string_view. To compile the mongocxx driver for pre-C++17, you
must choose one of the following implementations for these features:

MNMLSTC/core (default for non-Windows platforms)
Select with -DBSONCXX_POLY_USE_MNMLSTC=1. NOTE: This option
vendors a header-only installation of MNMLSTC/core into the bsoncxx
library installation and will therefore download MLNMLSTC from GitHub
during the build process. If you already have an available version of
MNMLSTC on your system, you can avoid the download step by using
-DBSONCXX_POLY_USE_SYSTEM_MNMLSTC.

Boost (default for Windows platforms)
Select with -DBSONCXX_POLY_USE_BOOST=1. This is currently the
only option if you are using a version of MSVC that does not support
C++17.

std::experimental
Select with -DBSONCXX_POLY_USE_STD_EXPERIMENTAL=1. If your
toolchain’s standard library provides optional and
string_view in the namespace std::experimental, you can use
this option. Be aware that your standard library’s
std::experimental implementation may change over time,
breaking binary compatibility in unexpected ways. Note that this
polyfill is not recommended and is unsupported.

Most users should be fine sticking with the default. However, if you
have an existing application which makes heavy use of one of the
available libraries, you may prefer to build the mongocxx driver
against the same library.

DO NOT change your project’s polyfill if you need to create a
stable binary interface.

Step 3: Download the latest version of the mongocxx driver.

To get the source via git, the releases/stable branch will track the most
recent stable release. For example, to work from a shallow checkout of the
stable release branch:

Make sure you change to the build directory of whatever source tree you
obtain.

Step 4: Configure the driver

On Unix systems, libmongoc installs into /usr/local by default. Without additional
configuration, mongocxx installs into its local build directory as a courtesy to those who build
from source. To configure mongocxx for installation into /usr/local as well, use the following
cmake command:

The example above assumes:
* Boost is found in C:\local\boost_1_60_0.
* libmongoc is found in C:\mongo-c-driver.
* mongocxx is to be installed into C:\mongo-cxx-driver.

For building with Visual Studio 2017 (without a C++17 polyfill), it is necessary to configure with
an additional option, /Zc:__cplusplus to opt into the correct definition of __cplusplus
(problem described here):

Users have the option to build mongocxx as a shared library that has statically linked
libmongoc. This is not recommended for novice users. A user can enable this behavior with the
-DBUILD_SHARED_LIBS_WITH_STATIC_MONGOC option:

Step 5: Build and install the driver

If you are using the default MNMLSTC polyfill and are installing to a
directory requiring root permissions, you should install the polyfill with
sudo before running make so you don’t have to run all of make with
sudo:

# Only for MNMLSTC polyfill
sudo make EP_mnmlstc_core

Once MNMLSTC is installed, or if you are using a different polyfill,
build and install the driver:

make && sudo make install

The driver can be uninstalled at a later time in one of two ways. First,
the uninstall target can be called:

sudo make uninstall

Second, the uninstall script can be called:

sudo /opt/mongo-cxx-driver/share/mongo-cxx-driver/uninstall.sh

On Windows, build and install from the command line like this:

msbuild.exe ALL_BUILD.vcxproj
msbuild.exe INSTALL.vcxproj

On Windows, the driver can be uninstalled at a later time in one of two
ways. First, the uninstall project can be called:

msbuild.exe generate_uninstall\uninstall.vcxproj

Second, the uninstall script can be called:

C:\opt\mongo-cxx-driver\share\mongo-cxx-driver\uninstall.cmd

Additional Options for Integrators

In the event that you are building the BSON C++ library and/or the C++ driver to embed with other components and you wish to avoid the potential for collision with components installed from a standard build or from a distribution package manager, you can make use of the BSONCXX_OUTPUT_BASENAME and MONGOCXX_OUTPUT_BASENAME options to cmake.

The above command would produce libraries named libcustom_bsoncxx.so and libcustom_mongocxx.so (or with the extension appropriate for the build platform). Those libraries could be placed in a standard system directory or in an alternate location and could be linked to by specifying something like -lcustom_mongocxx -lcustom_bsoncxx on the linker command line (possibly adjusting the specific flags to those required by your linker).

Step 6: Test your installation

Save the following source file with the filename test.cpp
underneath any directory:

Compiling with the help of CMake

If you are using CMake for your project, you can use the find_package()
directive to import targets which can be used to link to your build
targets. If you have installed mongocxx or libmongoc to a
non-standard location on your system, you will need to set
CMAKE_PREFIX_PATH to the library installation prefix (specified at
build time with CMAKE_INSTALL_PREFIX) when running cmake.

In the mongocxx source repository (versions 3.2.x or newer only), see
the directory examples/projects/mongocxx/cmake for an example CMake
application which uses the shared library (the default option), and an
example CMake application which uses the static library (advanced users
only).

Advanced users only: here is an example expansion on the same system of
the compilation line above when static libraries are being used. Note
that the preprocessor defines MONGOCXX_STATIC and BSONCXX_STATIC must
be defined in all source files that include mongocxx headers; failure to
do so will result in difficult-to-diagnose linker errors.

Compiling with MSVC

To compile on MSVC, you will need to setup your project to include all the
necessary include paths, library paths, preprocessor defines, and link
libraries. To do this, you can set these values either by the UI or by
editing the XML .vcxproj file directly. To confirm you have everything
setup correctly, here are the PropertyGroup and ItemDefinitionGroup
settings for a Debug x64 build as an example: