Docs Menu

Docs HomeC++ Driver

Installation on Windows

On this page

  • Step 1: Choose a C++17 polyfill
  • Step 2: Download the latest version of the mongocxx driver
  • Step 3: Configure the driver
  • Step 4: Build and install the driver

First, choose a C++17 polyfill library.

The most reliable starting point for building the mongocxx driver is the latest release tarball.

The mongocxx releases page will have links to the release tarball for the version you wish you install. For example, to download version 3.10.1:

curl -OL https://github.com/mongodb/mongo-cxx-driver/releases/download/r3.10.1/mongo-cxx-driver-r3.10.1.tar.gz
tar -xzf mongo-cxx-driver-r3.10.1.tar.gz
cd mongo-cxx-driver-r3.10.1/build

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

On Windows, the C++ driver is configured as follows (adjusting the path of the CMake executable as appropriate to your system):

'C:\Program Files (x86)\CMake\bin\cmake.exe' .. \
-G "Visual Studio 14 2015" -A "x64" \
-DBOOST_ROOT=C:\local\boost_1_60_0 \
-DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver

The example above assumes:

  • Boost is found in C:\local\boost_1_60_0.

  • mongocxx is to be installed into C:\mongo-cxx-driver.

To build with Visual Studio 2017 without a C++17 polyfill, configure as follows:

'C:\Program Files (x86)\CMake\bin\cmake.exe' .. \
-G "Visual Studio 15 2017" -A "x64" \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver \

To build versions 3.7.0 and older without a C++17 polyfill, it is necessary to configure with additional options:

'C:\Program Files (x86)\CMake\bin\cmake.exe' .. \
-G "Visual Studio 15 2017" -A "x64" \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_CXX_FLAGS="/Zc:__cplusplus /EHsc" \
-DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver \
cmake .. \
-DLIBMONGOC_DIR=C:\mongo-c-driver \
-DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver

Build and install the driver. Use --config to select a build configuration (e.g. Debug, RelWithDebInfo, Release):

cmake --build . --config RelWithDebInfo
cmake --build . --target install --config RelWithDebInfo

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

cmake --build . --target uninstall

Second, the uninstall script can be called:

C:\opt\mongo-cxx-driver\share\mongo-cxx-driver\uninstall.cmd
←  InstallationInstallation on macOS →