How to build MongoDB C++ driver
This solution succeeded on a machine with the following characteristics:
- Windows XP SP3 32-bit
- Visual Studio Express 2010 (VC 10)
I used D:\MongoDBcplusplusClient as a working directory (I installed there all the prerequisites).
Process:
Download MongoDB C++ driver:
https://github.com/mongodb/mongo-cxx-driver
You can make a clone using Git or download it as a .zip file (I did the second).You will get a file like mongo-cxx-driver-legacy.zip. Extract it to the folder mongo-cxx-driver-legacy inside your working directory.
Download Boost prebuilt windows binaries. ATTENTION!!! You should use a specific version of Boost. In my case version 1.52 did the trick. You can download it from here:
http://boost.teeks99.com/
I downloaded the boost_1_52_0-vc32-bin.exe self-extracting exe. Put it on your working directory and run it. It will create a folder (something like lib32) that will contain the boost binaries (.lib and .dll files)
Download Boost source code (.h files). Of course these should be from the same version as in Step 2. I downloaded them from here:
http://sourceforge.net/projects/boost/files/boost/1.52.0/
You will get a file boost_1_52_0.zip which you can extract at boost_1_52_0 folder.
Download Python. In this example I downloaded version 2.7.9 and specifically the Windows x86 MSI installer from here:
https://www.python.org/downloads/release/python-279/
Download Scons from here:
http://www.scons.org/download.php
I downloaded the Windows installer (scons-2.3.4-setup.exe) and installed Scons at the Python directory (in my case C:\Python27).
Download msinttypes from here:
https://code.google.com/p/msinttypes/
(You should include these header files to the project that uses the driver)
Go to Start->Run… and in the Run box write cmd. In the opened command prompt window navigate to the folder at which you extracted mongo driver at Step 1. In my case I did:
cd D:\ D:\MongoDBcplusplusClient\mongo-cxx-driver-legacy\mongo-cxx-driver-legacy
Build the driver using Scons. In the directory you navigated at Step 7 write:
scons
--prefix=D:\MongoDBcplusplusClient\mongo-cxx-driver-legacy\mongo-cxx-driver-legacy
--cpppath=D:\MongoDBcplusplusClient\boost_1_52_0\boost_1_52_0
--libpath= D:\MongoDBcplusplusClient\lib32
--win-version-min=xpsp3 install
and hit Enter.
The --prefix flag specifies the target directory at which the .lib file of the driver will be created, --cpppath specifies the folder at which the Boost header files are located and the --libpath the path to Boost .lib files. Of course you should change the path to yours. A file named libmongoclient-s.lib will be created at the --prefix/lib path.
If you want to build the driver with debugging enabled you should use the following command:
scons
--prefix=D:\MongoDBcplusplusClient\mongo-cxx-driver-legacy\mongo-cxx-driver-legacy
--cpppath=D:\MongoDBcplusplusClient\boost_1_52_0\boost_1_52_0
--libpath= D:\MongoDBcplusplusClient\lib32
--win-version-min=xpsp3
--dbg=on install
A file named libmongoclient-sgd.lib will be created at the --prefix/lib path.
At Windows Explorer navigate to the folder at which MongoDB C++ driver is installed, go into the subfolder lib (in my case this was D:\MongoDBcplusplusClient\mongo-cxx-driver-legacy\mongo-cxx-driver-legacy\lib) and rename the file libmongoclient-s.lib to mongoclient.lib and the libmongoclient-sgd.lib to mongoclient-gd.lib.
Open Visual Studio 2010 Express and open the project at which you want to use the MongoDB C++ driver. You should specify the dependencies. Right click on project’s name at solution explorer (left column) and hit Properties.
Go to C/C++ → General and at Additional Include Directories add:
a) Boost header files directory (in my case D:\MongoDBcplusplusClient\boost_1_52_0\boost_1_52_0)
b) MongoDB C++ driver header files directory (in my case
D:\MongoDBcplusplusClient\mongo-cxx-driver-legacy\mongo-cxx-driver
legacy\include)
c) Cstdint types header files directory (in my case
:\MongoDBcplusplusClient\msinttypes-r26 )
Go to Linker → General and at Additional Library Directories add:
a) Boost .lib files directory (in my case D:\MongoDBcplusplusClient\lib32)
b) MongoDB C++ driver .lib files directory (in my case D:\MongoDBcplusplusClient\mongo-cxx-driver-legacy\mongo-cxx-driver-legacy\lib)
After these steps the project that uses the driver will be successfully built both in release and debug configurations.