.\" Man page generated from reStructuredText. . .TH "MONGOC_INSTALLING" "3" "Jun 04, 2021" "1.17.6" "libmongoc" .SH NAME mongoc_installing \- Installing the MongoDB C Driver (libmongoc) and BSON library (libbson) . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .sp The following guide will step you through the process of downloading, building, and installing the current release of the MongoDB C Driver (libmongoc) and BSON library (libbson). .SH SUPPORTED PLATFORMS .sp The MongoDB C Driver is \fI\%continuously tested\fP on a variety of platforms including: .INDENT 0.0 .IP \(bu 2 Archlinux .IP \(bu 2 Debian 9.2, 10.0 .IP \(bu 2 macOS 10.14 .IP \(bu 2 Microsoft Windows Server 2008, 2016 .IP \(bu 2 RHEL 6.2, 7.0, 7.1, 8.2 .IP \(bu 2 Ubuntu 16.04, 18.04 .IP \(bu 2 Clang 3.4, 3.5, 3.7, 3.8, 6.0 .IP \(bu 2 GCC 4.8, 4.9, 5.4, 6.3, 8.2, 8.3 .IP \(bu 2 MinGW\-W64 .IP \(bu 2 Visual Studio 2013, 2015, 2017 .IP \(bu 2 x86, x86_64, ARM (aarch64), Power8 (ppc64le), zSeries (s390x) .UNINDENT .SH INSTALL LIBMONGOC WITH A PACKAGE MANAGER .sp Several Linux distributions provide packages for libmongoc and its dependencies. One advantage of installing libmongoc with a package manager is that its dependencies (including libbson) will be installed automatically. If you choose to install libmongoc from distribution packages, use the package manager to confirm the version being installed is sufficient for your needs. .sp The libmongoc package is available on recent versions of Debian and Ubuntu. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ apt\-get install libmongoc\-1.0\-0 .ft P .fi .UNINDENT .UNINDENT .sp On Fedora, a mongo\-c\-driver package is available in the default repositories and can be installed with: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ dnf install mongo\-c\-driver .ft P .fi .UNINDENT .UNINDENT .sp On recent Red Hat systems, such as CentOS and RHEL 7, a mongo\-c\-driver package is available in the \fI\%EPEL\fP repository. To check which version is available, see \fI\%https://apps.fedoraproject.org/packages/mongo\-c\-driver\fP\&. The package can be installed with: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ yum install mongo\-c\-driver .ft P .fi .UNINDENT .UNINDENT .sp On macOS systems with Homebrew, the mongo\-c\-driver package can be installed with: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ brew install mongo\-c\-driver .ft P .fi .UNINDENT .UNINDENT .SH INSTALL LIBBSON WITH A PACKAGE MANAGER .sp The libbson package is available on recent versions of Debian and Ubuntu. If you have installed libmongoc, then libbson will have already been installed as a dependency. It is also possible to install libbson without libmongoc. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ apt\-get install libbson\-1.0\-0 .ft P .fi .UNINDENT .UNINDENT .sp On Fedora, a libbson package is available in the default repositories and can be installed with: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ dnf install libbson .ft P .fi .UNINDENT .UNINDENT .sp On recent Red Hat systems, such as CentOS and RHEL 7, a libbson package is available in the \fI\%EPEL\fP repository. To check which version is available, see \fI\%https://apps.fedoraproject.org/packages/libbson\fP\&. The package can be installed with: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ yum install libbson .ft P .fi .UNINDENT .UNINDENT .SH BUILD ENVIRONMENT .SS Build environment on Unix .SS Prerequisites for libmongoc .sp OpenSSL is required for authentication or for TLS connections to MongoDB. Kerberos or LDAP support requires Cyrus SASL. .sp To install all optional dependencies on RedHat / Fedora: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ sudo yum install cmake openssl\-devel cyrus\-sasl\-devel .ft P .fi .UNINDENT .UNINDENT .sp On Debian / Ubuntu: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ sudo apt\-get install cmake libssl\-dev libsasl2\-dev .ft P .fi .UNINDENT .UNINDENT .sp On FreeBSD: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ su \-c \(aqpkg install cmake openssl cyrus\-sasl\(aq .ft P .fi .UNINDENT .UNINDENT .SS Prerequisites for libbson .sp The only prerequisite for building libbson is \fBcmake\fP\&. The command lines above can be adjusted to install only \fBcmake\fP\&. .SS Build environment on macOS .sp Install the XCode Command Line Tools: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ xcode\-select \-\-install .ft P .fi .UNINDENT .UNINDENT .sp The \fBcmake\fP utility is also required. First \fI\%install Homebrew according to its instructions\fP, then: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ brew install cmake .ft P .fi .UNINDENT .UNINDENT .SS Build environment on Windows with Visual Studio .sp Building on Windows requires Windows Vista or newer and Visual Studio 2010 or newer. Additionally, \fBcmake\fP is required to generate Visual Studio project files. Installation of these components on Windows is beyond the scope of this document. .SS Build environment on Windows with MinGW\-W64 and MSYS2 .sp Install MSYS2 from \fI\%msys2.github.io\fP\&. Choose the x86_64 version, not i686. .sp Open the MingGW shell with \fBc:\emsys64\eming64.exe\fP (not the msys2_shell). Install dependencies: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ pacman \-\-noconfirm \-Syu $ pacman \-\-noconfirm \-S mingw\-w64\-x86_64\-gcc mingw\-w64\-x86_64\-cmake $ pacman \-\-noconfirm \-S mingw\-w64\-x86_64\-extra\-cmake\-modules make tar $ pacman \-\-noconfirm \-S mingw64/mingw\-w64\-x86_64\-cyrus\-sasl .ft P .fi .UNINDENT .UNINDENT .SH CONFIGURING THE BUILD .sp Before building libmongoc and/or libbson, it is necessary to configure, or prepare, the build. The steps to prepare the build depend on how you obtained the source code and the build platform. .SS Preparing a build from a release tarball .sp The most recent release of libmongoc and libbson, both of which are included in mongo\-c\-driver, can be \fI\%downloaded here\fP\&. The instructions in this document utilize \fBcmake\fP\(aqs out\-of\-source build feature to keep build artifacts separate from source files. While the \fB$\fP prompt is used throughout, the instructions below will work on Linux, macOS, and Windows (assuming that CMake is in the user\(aqs shell path in all cases). See the subsequent sections for additional platform\-specific instructions. .sp The following snippet will download and extract the driver, and configure it: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ wget \fI\%https://github.com/mongodb/mongo\-c\-driver/releases/download/\fP1.17.6/mongo\-c\-driver\-1.17.6\&.tar.gz $ tar xzf mongo\-c\-driver\-1.17.6\&.tar.gz $ cd mongo\-c\-driver\-1.17.6 $ mkdir cmake\-build $ cd cmake\-build $ cmake \-DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF .. .ft P .fi .UNINDENT .UNINDENT .sp The \fB\-DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF\fP option is recommended, see init\-cleanup\&. Another useful \fBcmake\fP option is \fB\-DCMAKE_BUILD_TYPE=Release\fP for a release optimized build and \fB\-DCMAKE_BUILD_TYPE=Debug\fP for a debug build. For a list of all configure options, run \fBcmake \-L ..\fP\&. .sp If \fBcmake\fP completed successfully, you will see a considerable amount of output describing your build configuration. The final line of output should look something like this: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C \-\- Build files have been written to: /home/user/mongo\-c\-driver\-1.17.6/cmake\-build .ft P .fi .UNINDENT .UNINDENT .sp If \fBcmake\fP concludes with anything different, then it is likely an error occurred. .sp mongo\-c\-driver contains a copy of libbson, in case your system does not already have libbson installed. The configuration will detect if libbson is not installed and use the bundled libbson. .sp Additionally, it is possible to build only libbson by setting the \fB\-DENABLE_MONGOC=OFF\fP option: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ cmake \-DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF \-DENABLE_MONGOC=OFF .. .ft P .fi .UNINDENT .UNINDENT .sp A build configuration description similar to the one above will be displayed, though with fewer entries. Once the configuration is complete, the selected items can be built and installed with these commands: .SS Preparing a build from a git repository clone .sp Clone the repository and prepare the build on the current master branch or a particular release tag: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ git clone \fI\%https://github.com/mongodb/mongo\-c\-driver.git\fP $ cd mongo\-c\-driver $ git checkout 1.17.6 # To build a particular release $ python build/calc_release_version.py > VERSION_CURRENT $ mkdir cmake\-build $ cd cmake\-build $ cmake \-DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF .. .ft P .fi .UNINDENT .UNINDENT .SS Preparing a build on Windows with Visual Studio .sp On the Windows platform with Visual Studio, it may be necessary to specify the CMake generator to use. This is especially important if multiple versions of Visual Studio are installed on the system or if alternate build tools (e.g., MinGW, MSYS2, Cygwin, etc.) are present on the system. Specifying the generator will ensure that the build configuration is known with certainty, rather than relying on the toolchain that CMake happens to find. .sp Start by generating Visual Studio project files. The following assumes you are compiling for 64\-bit Windows using Visual Studio 2015 Express, which can be freely downloaded from Microsoft. The sample commands utilize \fBcmake\fP\(aqs out\-of\-source build feature to keep build artifacts separate from source files. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ cd mongo\-c\-driver\-1.17.6 $ mkdir cmake\-build $ cd cmake\-build $ cmake \-G "Visual Studio 14 2015 Win64" \e "\-DCMAKE_INSTALL_PREFIX=C:\emongo\-c\-driver" \e "\-DCMAKE_PREFIX_PATH=C:\emongo\-c\-driver" \e .. .ft P .fi .UNINDENT .UNINDENT .sp (Run \fBcmake \-LH ..\fP for a list of other options.) .sp To see a complete list of the CMake generators available on your specific system, use a command like this: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ cmake \-\-help .ft P .fi .UNINDENT .UNINDENT .SH EXECUTING A BUILD .SS Building on Unix, macOS, and Windows (MinGW\-W64 and MSYS2) .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ cmake \-\-build . $ sudo cmake \-\-build . \-\-target install .ft P .fi .UNINDENT .UNINDENT .sp (Note that the \fBsudo\fP command may not be applicable or available depending on the configuration of your system.) .sp In the above commands, the first relies on the default target which builds all configured components. For fine grained control over what gets built, the following command can be used (for Ninja and Makefile\-based build systems) to list all available targets: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ cmake \-\-build . help .ft P .fi .UNINDENT .UNINDENT .SS Building on Windows with Visual Studio .sp Once the project files are generated, the project can be opened directly in Visual Studio or compiled from the command line. .sp Build using the CMake build tool mode: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ cmake \-\-build . \-\-config RelWithDebInfo .ft P .fi .UNINDENT .UNINDENT .sp Visual Studio\(aqs default build type is \fBDebug\fP, but we recommend a release build with debug info for production use. Now that libmongoc and libbson are compiled, install them. Components will be installed to the path specified by \fBCMAKE_INSTALL_PREFIX\fP\&. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ cmake \-\-build . \-\-config RelWithDebInfo \-\-target install .ft P .fi .UNINDENT .UNINDENT .sp You should now see libmongoc and libbson installed in \fBC:\emongo\-c\-driver\fP .sp For Visual Studio 2019 (16.4 and newer), this command can be used to list all available targets: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ cmake \-\-build . \-\- /targets .ft P .fi .UNINDENT .UNINDENT .sp Alternately, you can examine the files matching the glob \fB*.vcxproj\fP in the \fBcmake\-build\fP directory. .sp To use the driver libraries in your program, see visual\-studio\-guide\&. .SS Generating the documentation .sp Install \fI\%Sphinx\fP, then: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ cmake \-DENABLE_MAN_PAGES=ON \-DENABLE_HTML_DOCS=ON .. $ cmake \-\-build . \-\-target mongoc\-doc .ft P .fi .UNINDENT .UNINDENT .sp To build only the libbson documentation: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ cmake \-DENABLE_MAN_PAGES=ON \-DENABLE_HTML_DOCS=ON .. $ cmake \-\-build . \-\-target bson\-doc .ft P .fi .UNINDENT .UNINDENT .sp The \fB\-DENABLE_MAN_PAGES=ON\fP and \fB\-DENABLE_HTML_DOCS=ON\fP can also be added as options to a normal build from a release tarball or from git so that the documentation is built at the same time as other components. .SS Uninstalling the installed components .sp There are two ways to uninstall the components that have been installed. The first is to invoke the uninstall program directly. On Linux/Unix: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ sudo /usr/local/share/mongo\-c\-driver/uninstall.sh .ft P .fi .UNINDENT .UNINDENT .sp On Windows: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ C:\emongo\-c\-driver\eshare\emongo\-c\-driver\euninstall.bat .ft P .fi .UNINDENT .UNINDENT .sp 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: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ sudo cmake \-\-build . \-\-target uninstall .ft P .fi .UNINDENT .UNINDENT .sp The second approach simply invokes the uninstall program referenced in the first approach. .SH ADDITIONAL OPTIONS FOR INTEGRATORS .sp 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 \fBBSON_OUTPUT_BASENAME\fP and \fBMONGOC_OUTPUT_BASENAME\fP options to \fBcmake\fP\&. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C $ cmake \-DBSON_OUTPUT_BASENAME=custom_bson \-DMONGOC_OUTPUT_BASENAME=custom_mongoc .. .ft P .fi .UNINDENT .UNINDENT .sp The above command would produce libraries named \fBlibcustom_bson.so\fP and \fBlibcustom_mongoc.so\fP (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 \fB\-lcustom_mongoc \-lcustom_bson\fP on the linker command line (possibly adjusting the specific flags to those required by your linker). .SH AUTHOR MongoDB, Inc .SH COPYRIGHT 2017-present, MongoDB, Inc .\" Generated by docutils manpage writer. .