Docs Menu
Docs Home
/ / /
C++ Driver
/

Download and Install

1

Before you being developing, ensure you have the following dependencies installed in your development environment:

  • Compiler that supports C++17, such as GCC, Clang, or Visual Studio

  • CMake v3.15 or later

  • pkg-config

Note

C++17 Polyfills

This tutorial configures the C++ driver to use the C++17 standard library. If you want to install the driver for pre-C++17 configurations, you must choose a C++17 polyfill library. To learn more about C++17 polyfills, see the Choose a C++17 Polyfill guide.

2

To download the latest version of the C++ driver from the mongo-cxx-driver Github repository, run the following commands in your shell from your root directory:

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

Select the tab corresponding to your operating system and run following command from your mongo-cxx-driver-r3.11.0/build directory:

cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DMONGOCXX_OVERRIDE_DEFAULT_INSTALL_PREFIX=OFF

This command instructs CMake to install mongocxx into the /usr/local directory.

'C:\<path>\cmake.exe' .. \
-G "Visual Studio <version> <year>" -A "x64" \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_INSTALL_PREFIX=C:\mongo-cxx-driver \

This command instructs CMake to install mongocxx into the C:\mongo-cxx-driver directory. Replace the following placeholder values:

  • <path>: The path to your CMake executable

  • <version>: Your Visual Studio version number

  • <year>: The year corresponding to your Visual Studio version

4

Select the tab corresponding to your operating system and run following commands to install the driver:

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

After you complete these steps, you have the C++ driver installed on your machine.

Note

If you run into issues on this step, ask for help in the MongoDB Community Forums or submit feedback by using the Rate this page tab on the right or bottom right side of this page.

Back

Get Started