Installing the MongoDB C Driver (libmongoc) and BSON library (libbson)#

Note

Much of this section of documentation has been rewritten and moved: Obtaining the MongoDB C Driver Libraries

Supported Platforms#

Install libmongoc with a Package Manager#

Install libbson with a Package Manager#

Docker image#

You can find a Docker image in Docker Hub along with example usage of using libmongoc to ping a MongoDB database from within a Docker container.

Build environment#

Uninstalling the installed components#

There are two ways to uninstall the components that have been installed. The first is to invoke the uninstall program directly. On Linux/Unix:

$ sudo /usr/local/share/mongo-c-driver/uninstall.sh

On Windows:

$ C:\mongo-c-driver\share\mongo-c-driver\uninstall.bat

The second way to uninstall is from within the build directory, assuming that it is in the exact same state as when the install command was invoked:

$ sudo cmake --build . --target uninstall

The second approach simply invokes the uninstall program referenced in the first approach.

Dealing with Build Failures#

If your attempt to build the C driver fails, please see the README for instructions on requesting assistance.

Additional Options for Integrators#

In the event that you are building the BSON 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 BSON_OUTPUT_BASENAME and MONGOC_OUTPUT_BASENAME options to cmake.

$ cmake -DBSON_OUTPUT_BASENAME=custom_bson -DMONGOC_OUTPUT_BASENAME=custom_mongoc ..

The above command would produce libraries named libcustom_bson.so and libcustom_mongoc.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_mongoc -lcustom_bson on the linker command line (possibly adjusting the specific flags to those required by your linker).