1MONGOC_INSTALLING(3)           MongoDB C Driver           MONGOC_INSTALLING(3)
2
3
4

NAME

6       mongoc_installing  -  Installing  the  MongoDB C Driver (libmongoc) and
7       BSON library (libbson)
8
9       The following guide will step you through the process  of  downloading,
10       building,  and  installing  the current release of the MongoDB C Driver
11       (libmongoc) and BSON library (libbson).
12

SUPPORTED PLATFORMS

14       The MongoDB C Driver is continuously tested  on  variety  of  platforms
15       including:
16
17       · Archlinux
18
19       · Debian 9.2
20
21       · macOS 10.12
22
23       · Microsoft Windows Server 2008
24
25       · RHEL 7.0, 7.1, 7.2
26
27       · Ubuntu 16.04, 18.04
28
29       · Clang 3.4, 3.5, 3.7, 3.8
30
31       · GCC 4.6, 4.8, 4.9, 5.4, 6.3
32
33       · MinGW-W64
34
35       · Visual Studio 2010, 2013, 2015
36
37       · x86, x86_64, ARM (aarch64), Power8 (ppc64le), zSeries (s390x)
38

INSTALL LIBMONGOC WITH A PACKAGE MANAGER

40       Several  Linux  distributions  provide  packages  for libmongoc and its
41       dependencies. One advantage of installing libmongoc with a package man‐
42       ager  is  that  its  dependencies (including libbson) will be installed
43       automatically.
44
45       The libmongoc package is available on recent  versions  of  Debian  and
46       Ubuntu.
47
48          $ apt-get install libmongoc-1.0-0
49
50       On Fedora, a mongo-c-driver package is available in the default reposi‐
51       tories and can be installed with:
52
53          $ dnf install mongo-c-driver
54
55       On recent Red Hat systems, such as CentOS and RHEL 7, a  mongo-c-driver
56       package  is available in the EPEL repository. To check which version is
57       available, see  https://apps.fedoraproject.org/packages/mongo-c-driver.
58       The package can be installed with:
59
60          $ yum install mongo-c-driver
61

INSTALL LIBBSON WITH A PACKAGE MANAGER

63       The  libbson  package  is  available  on  recent versions of Debian and
64       Ubuntu. If you have installed libmongoc, then libbson will have already
65       been  installed as a dependency. It is also possible to install libbson
66       without libmongoc.
67
68          $ apt-get install libbson-1.0
69
70       On Fedora, a libbson package is available in the  default  repositories
71       and can be installed with:
72
73          $ dnf install libbson
74
75       On recent Red Hat systems, such as CentOS and RHEL 7, a libbson package
76       is available in the EPEL repository. To check which version  is  avail‐
77       able, see https://apps.fedoraproject.org/packages/libbson.  The package
78       can be installed with:
79
80          $ yum install libbson
81

BUILDING ON UNIX

83   Prerequisites for libmongoc
84       OpenSSL is required for authentication or for SSL connections  to  Mon‐
85       goDB. Kerberos or LDAP support requires Cyrus SASL.
86
87       To install all optional dependencies on RedHat / Fedora:
88
89          $ sudo yum install cmake openssl-devel cyrus-sasl-devel
90
91       On Debian / Ubuntu:
92
93          $ sudo apt-get install cmake libssl-dev libsasl2-dev
94
95       On FreeBSD:
96
97          $ su -c 'pkg install cmake openssl cyrus-sasl'
98
99   Prerequisites for libbson
100       The  only prerequisite for building libbson is cmake. The command lines
101       above can be adjusted to install only cmake.
102
103   Building from a release tarball
104       Unless you intend to contribute to mongo-c-driver and/or  libbson,  you
105       will want to build from a release tarball.
106
107       The  most  recent  release  of libmongoc and libbson, both of which are
108       included in mongo-c-driver, can be downloaded here. The instructions in
109       this document utilize cmake's out-of-source build feature to keep build
110       artifacts separate from source files.
111
112       The following snippet will download and extract the driver, and config‐
113       ure it:
114
115          $ wget https://github.com/mongodb/mongo-c-driver/releases/download/x.y.z/mongo-c-driver-x.y.z.tar.gz
116          $ tar xzf mongo-c-driver-x.y.z.tar.gz
117          $ cd mongo-c-driver-x.y.z
118          $ mkdir cmake-build
119          $ cd cmake-build
120          $ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
121
122       The  -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF option is recommended, see
123       init-cleanup. Another useful cmake option is -DCMAKE_BUILD_TYPE=Release
124       for  a release optimized build and -DCMAKE_BUILD_TYPE=Debug for a debug
125       build. For a list of all configure options, run cmake -L ...
126
127       If cmake completed successfully, you will see a considerable amount  of
128       output  describing  your  build configuration. The final line of output
129       should look something like this:
130
131          -- Build files have been written to: /home/user/mongo-c-driver-x.y.z/cmake-build
132
133       If cmake concludes with anything different, then  there  is  likely  an
134       error  or some other problem with the build. Review the output to iden‐
135       tify and correct the problem.
136
137       mongo-c-driver contains a copy of libbson, in case your system does not
138       already have libbson installed. The build will detect if libbson is not
139       installed and use the bundled libbson.
140
141       Additionally, it is possible to build only libbson by setting the -DEN‐
142       ABLE_MONGOC=OFF option:
143
144          $ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -DENABLE_MONGOC=OFF ..
145
146       A build configuration description similar to the one above will be dis‐
147       played, though with fewer entries. Once the configuration is  complete,
148       the selected items can be built and installed with these commands:
149
150          $ make
151          $ sudo make install
152
153       There  are  two  ways  to  uninstall  the  components  that  have  been
154       installed.  The first is to invoke the uninstall program directly.   On
155       Linux/Unix:
156
157          $ sudo /usr/local/share/mongo-c-driver/uninstall.sh
158
159       On Windows:
160
161          C:\Users\user> C:\mongo-c-driver\share\mongo-c-driver\uninstall.bat
162
163       The  second way to uninstall is from within the build directory, assum‐
164       ing that it is in the exact same state as when the install command  was
165       invoked:
166
167          $ sudo make uninstall
168
169       The  second approach simply invokes the uninstall program referenced in
170       the first approach.
171
172   Building from git
173       Clone the repository and build  the  current  master  or  a  particular
174       release tag:
175
176          $ git clone https://github.com/mongodb/mongo-c-driver.git
177          $ cd mongo-c-driver
178          $ git checkout x.y.z  # To build a particular release
179          $ python build/calc_release_version.py > VERSION_CURRENT
180          $ mkdir cmake-build
181          $ cd cmake-build
182          $ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
183          $ make
184          $ sudo make install
185
186   Generating the documentation
187       Install Sphinx, then:
188
189          $ cmake -DENABLE_MAN_PAGES=ON -DENABLE_HTML_DOCS=ON ..
190          $ make mongoc-doc
191
192       To build only the libbson documentation:
193
194          $ cmake -DENABLE_MAN_PAGES=ON -DENABLE_HTML_DOCS=ON ..
195          $ make bson-doc
196
197       The  -DENABLE_MAN_PAGES=ON  and -DENABLE_HTML_DOCS=ON can also be added
198       as options to a normal build from a release tarball or from git so that
199       the documentation is built at the same time as other components.
200

BUILDING ON MACOS

202       Install the XCode Command Line Tools:
203
204          $ xcode-select --install
205
206       The cmake utility is also required. First install Homebrew according to
207       its instructions, then:
208
209          $ brew install cmake
210
211       Download the latest release tarball:
212
213          $ curl -LO https://github.com/mongodb/mongo-c-driver/releases/download/x.y.z/mongo-c-driver-x.y.z.tar.gz
214          $ tar xzf mongo-c-driver-x.y.z.tar.gz
215          $ cd mongo-c-driver-x.y.z
216
217       Build and install the driver:
218
219          $ mkdir cmake-build
220          $ cd cmake-build
221          $ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
222
223       All of the same variations described above (e.g., building  only  libb‐
224       son,  building documentation, etc.) are available when building on mac‐
225       OS.
226

BUILDING ON WINDOWS WITH VISUAL STUDIO

228       Building on Windows requires Windows Vista or newer and  Visual  Studio
229       2010  or newer. Additionally, cmake is required to generate Visual Stu‐
230       dio project files.
231
232       Let's start by generating Visual Studio project  files.  The  following
233       assumes  we  are  compiling for 64-bit Windows using Visual Studio 2015
234       Express, which can be freely downloaded from Microsoft. We will be uti‐
235       lizing cmake's out-of-source build feature to keep build artifacts sep‐
236       arate from source files.
237
238          cd mongo-c-driver-x.y.z
239          mkdir cmake-build
240          cd cmake-build
241          cmake -G "Visual Studio 14 2015 Win64" \
242            "-DCMAKE_INSTALL_PREFIX=C:\mongo-c-driver" \
243            "-DCMAKE_PREFIX_PATH=C:\mongo-c-driver" \
244            ..
245
246       (Run cmake -LH .. for a list of other options.)
247
248       Now that we have project  files  generated,  we  can  either  open  the
249       project  in Visual Studio or compile from the command line. Let's build
250       using the command line program msbuild.exe:
251
252          msbuild.exe /p:Configuration=RelWithDebInfo ALL_BUILD.vcxproj
253
254       Visual Studio's default build type is Debug, but we recommend a release
255       build  with debug info for production use. Now that libmongoc and libb‐
256       son are  compiled,  let's  install  them  using  msbuild.  It  will  be
257       installed to the path specified by CMAKE_INSTALL_PREFIX.
258
259          msbuild.exe INSTALL.vcxproj
260
261       You should now see libmongoc and libbson installed in C:\mongo-c-driver
262
263       To use the driver libraries in your program, see visual-studio-guide.
264

BUILDING ON WINDOWS WITH MINGW-W64 AND MSYS2

266       Install  MSYS2  from  msys2.github.io.  Choose  the x86_64 version, not
267       i686.
268
269       Open the MingGW shell with c:\msys64\ming64.exe (not the  msys2_shell).
270       Install dependencies:
271
272          pacman --noconfirm -Syu
273          pacman --noconfirm -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake
274          pacman --noconfirm -S mingw-w64-x86_64-extra-cmake-modules make tar
275          pacman --noconfirm -S mingw64/mingw-w64-x86_64-cyrus-sasl
276
277       Download  and  untar the latest tarball, enter its directory, and build
278       with CMake:
279
280          mkdir cmake-build
281          cd cmake-build
282          CC=/mingw64/bin/gcc.exe /mingw64/bin/cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX="C:/mongo-c-driver" -DCMAKE_C_FLAGS="-D__USE_MINGW_ANSI_STDIO=1" ..
283          make
284

AUTHOR

286       MongoDB, Inc
287
289       2017-present, MongoDB, Inc
290
291
292
293
2941.15.2                           Nov 06, 2019             MONGOC_INSTALLING(3)
Impressum