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

Download and Install

1

Before you being this tutorial, 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

Pre-C++17 Configurations

Although C++11 is the minimum supported language version, this tutorial configures the C++ driver to use the C++17 standard library as recommended by the C++17 Polyfill Configuration section. If you want to install the driver for pre-C++17 configurations, set the CMAKE_CXX_STANDARD configuration option to your C++ version. Then, the driver will automatically use bsoncxx library polyfill implementations for required C++17 features.

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/r4.0.0/mongo-cxx-driver-r4.0.0.tar.gz
tar -xzf mongo-cxx-driver-r4.0.0.tar.gz
cd mongo-cxx-driver-r4.0.0/build
3

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

cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_STANDARD=17

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