Building MongoDB C++ driver with Mingw64

This post is a summary of the steps needed to build the MongoDB C++ driver with Mingw64.


Why would one want to go through the trouble to build the C++ driver with Mingw64?

  • Portability of code
  • Ease cross-platform implementation (less #ifdef’s)
  • Same build tools on all operating systems (gcc)
  • Supporting more compilers is always good
  • Promoting open-source projects


First of all this post will use specific versions of tools, but making it work with other won’t be difficult.

The first thing that will be needed is mingw64. There are so many different versions available for download, but I used this one:


It uses win32 threads (instead of posix) and seh exception handling.

You will also need msys, which is a posix-like environment:


You should install  python and scons, this is needed to build the driver.

If you want SSL support you will need to grab OpenSSL:


You will also need boost:


Then you need to clone my fork of mongo-cxx-driver:

My fork


This section covers building each of the libraries.

msys and mingw64

In order to use msys and mingw64, first extract msys (you may need to install 7-zip) to C:\

In order to test this run C:\msys\msys.bat

The next step is extracting the mingw64 contents directly into the msys folder, overwriting any conflicts. Now run msys again and call

You should see a version message. You should also add C:\msys\bin to your path.


Now that the toolchain is installed we can start building the dependencies.

Extract openssl to a path easily found through msys. I usually extract it into the msys folder itself. It is important to use tar -xf from within msys and not 7-zip.

Open a msys shell and browse to the openssl folder.

The output will be in C:\msys\local\ssl\, copy the contents into C:\msys\local\.


Building boost is done in much the same way. But first browse to BOOST_ROOT\tools\build\v2\engine and invoke:

Now back in the boost root folder:

You will see that boost makes a folder boost-1_55 inside local/include, move the boost folder out so that local/include has the root boost include folder.

The fork

First clone the repository, then run the scons command.

The --mingw flag tells the modified SConstruct scripts that mingw is the compiler. --boost-postfix allows the user to add the strange postfixes of the boost libraries to the search path and linkage of the libs.

When using --sharedclient the examples will fail to build during the second phase (building the shared library). Although the statically linked examples still work.

That is all there is to it. Please let me know if you have any troubles in repeating the build process. Also please leave a comment.

11 Replies to “Building MongoDB C++ driver with Mingw64”

  1. Hello. I wan’t to limit mongodb write. So, I add some user on mongodb. But, when I start mongodb with –auth, then My Client use auth to connect failed. I get this message:
    caught SCRAM-SHA-1 mechanism support not compiled into client library.

    I compile c++ driver use –ssl. But It does’nt make the Install dir when compile finished. Only have some file and dir like this:

    |—-mongo(some .obj file)

    I try to use libmongoclient-s.lib. But I don’t know how to use it. Because:
    1、don’t have suit head file
    2、compile don’t link to libmongoclient-s.lib

    Please help me.

    some infomation:
    vs version: visual studio 2013
    mongodb c++ driver version: mongo-cxx-driver-legacy-1.1.0
    compile command:
    scons –32 –dynamic-boost=off –cpppath=”F:\boost_1_59_0″ –extrapath=”C:\OpenSSL-Win32″ — libpath=”F:\\boost_1_59_0\lib32-msvc-12.0″ –ssl –msvc-version=12.0 –dbg=on –dynamic-windows –sharedclient –prefix=”F:\driver” install

  2. how to using scons with the MinGW32 compiler,compile mongodb dynamic c++ library
    who can tell me how to change the original documents file SConstruct in mongo-cxx-driver-legacy: ,now it only support MSVC

Leave a Comment