C++ driver for MongoDB 1.6.0?

275 views
Skip to first unread message

Jason

unread,
Aug 9, 2010, 11:22:25 AM8/9/10
to mongodb-user
The release notes for MongoDB 1.6.0 state that the c++ client driver
is packaged in a separate tarball. However, I can't find the driver
now. Do I need to build it from the source? The documentation on
mongodb.org needs updated since it still states that the c++ client
driver is packaged in the main distribution.

The support for the c++ client driver is very frustrating. When
working with 1.4.4 using VS 2008 on Windows, I had to build the c++
client driver from source because the distributed build would not link
properly (and yes, I scoured the forums for a solution to no avail).

Eliot Horowitz

unread,
Aug 9, 2010, 11:59:08 AM8/9/10
to mongod...@googlegroups.com
The link is
http://fastdl.mongodb.org/cxx-driver/mongodb-linux-x86_64-v1.6-latest.tgz

working on the docs.

we know the c++ driver is a bit annoying at the moment, the new
package is the first step in trying to make it easer to work with.

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Paul Kalmar

unread,
Aug 9, 2010, 2:44:47 PM8/9/10
to mongodb-user
Is there a precompiled C++ client driver for Windows?

On Aug 9, 8:59 am, Eliot Horowitz <eliothorow...@gmail.com> wrote:
> The link ishttp://fastdl.mongodb.org/cxx-driver/mongodb-linux-x86_64-v1.6-latest...

Jason

unread,
Aug 9, 2010, 3:39:41 PM8/9/10
to mongodb-user
Thanks, but I'm looking for a precompiled C++ client driver for
Windows.

On Aug 9, 8:59 am, Eliot Horowitz <eliothorow...@gmail.com> wrote:
> The link ishttp://fastdl.mongodb.org/cxx-driver/mongodb-linux-x86_64-v1.6-latest...
>

Piotr Beling

unread,
Aug 9, 2010, 8:48:39 PM8/9/10
to mongodb-user
And what about package for ubuntu? Can We expect some very soon?

Eliot Horowitz

unread,
Aug 10, 2010, 11:41:24 AM8/10/10
to mongod...@googlegroups.com
For ubuntu, you can track: http://jira.mongodb.org/browse/SERVER-963

For windows - making pre-compiled libraries that work for most
situations seems to be very difficult. If someone can help - that
would definitely make it go faster.

On Mon, Aug 9, 2010 at 8:48 PM, Piotr Beling <qwa...@gmail.com> wrote:
> And what about package for ubuntu? Can We expect some very soon?
>

Jason

unread,
Aug 10, 2010, 7:42:13 PM8/10/10
to mongodb-user
So after struggling for hours to get a working C++ driver for MongoDB
(Windows w/ VS 2008), I'm at the end of my patience. Here's what I
did:

1. Downloaded the MongoDB 1.6.0 source code.
2. Installed and built all the necessary Boost 1.42 libraries.
3. Installed Python 2.6.5 and SCons 1.2.0.
4. Downloaded the SpiderMonkey 1.7.0 source code.
5. Built SpiderMonkey using the SCons script from mongodb/snippets.
6. Built MongoDB 1.6.0 client driver by executing "scons
mongoclient".

In my VS 2008 C++ project, I link to the driver using '#pragma
comment(lib, "mongoclient.lib")'. When I do a standard debug build,
everything works fine. However, when I do a standard release build,
as soon as I create a mongo::DBClientConnection object, it crashes
with the following:

HEAP[VIS.exe]: Invalid allocation size - CCCCCC10 (exceeded 7ffdefff)
First-chance exception at 0x7c812afb in VIS.exe: Microsoft C++
exception: std::bad_alloc at memory location 0x0012e6b0..
HEAP[VIS.exe]: Invalid allocation size - CCCCCC01 (exceeded 7ffdefff)
First-chance exception at 0x7c812afb in VIS.exe: Microsoft C++
exception: std::bad_alloc at memory location 0x0012e050..
First-chance exception at 0x7c812afb in VIS.exe: Microsoft C++
exception: [rethrow] at memory location 0x00000000..

Also, if I redo step 6 with "scons --release mongoclient", I am unable
to link to the resulting client library.
Following is a sampling of the errors I get. There have been other
posts with the same errors in previous versions. I have tried various
solutions such as ignoring libcmt.lib and msvcrt.lib, but they just
produce other linker errors.

1>mongoclient-release.lib(dbclient.obj) : error LNK2005: "public:
class std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > __thiscall std::basic_stringstream<char,struct
std::char_traits<char>,class std::allocator<char> >::str(void)const
" (?str@?$basic_stringstream@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@2@XZ) already defined in msvcprt.lib(MSVCP90.dll)

1>LIBCMT.lib(crtheap.obj) : error LNK2005: __malloc_crt already
defined in MSVCRT.lib(MSVCR90.dll)

1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > & __thiscall std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >::operator+=(class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > const &)" (??Y?$basic_string@DU?
$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@ABV01@@Z) already
defined in mongoclient-release.lib(dbclient.obj)

Any help would be appreciated as I've experienced similar issues with
MongoDB version 1.4.4.


On Aug 9, 8:59 am, Eliot Horowitz <eliothorow...@gmail.com> wrote:
> The link ishttp://fastdl.mongodb.org/cxx-driver/mongodb-linux-x86_64-v1.6-latest...
>

Jason

unread,
Aug 11, 2010, 2:33:55 PM8/11/10
to mongodb-user
Holy crap, finding the solution was painful, but I did it. So for
those of you who are trying to use the MongoDB C++ client driver with
VS 2008 on Windows 32-bit, here is what I did:

Install Boost
-------------

1. Download Boost 1.42 from http://www.boostpro.com/download/boost_1_42_setup.exe
2. Run Boost installer
a. Check the VC9.0 (VS 2008) option.
b. Check all VC9.0 multi-threaded options for the DateTime,
Filesystem, ProgramOptions, Regex, System, and Thread libraries.
Depending on your usage of MongoDB, you may not need all the multi-
threaded options.

Official instructions - http://www.mongodb.org/display/DOCS/Boost+and+Windows

Install Build Tools for MongoDB
-------------------------------

1. Install Python 2.6.5 from http://www.python.org/download/releases/2.6.5/
2. Install SCons 1.2.0 from
http://sourceforge.net/projects/scons/files/scons/1.2.0/scons-1.2.0.win32.exe/download
3. Add the Python scripts directory to your PATH (i.e. C:
\Python26\Scripts)

Official instructions - http://www.mongodb.org/display/DOCS/Building+with+Visual+Studio+2008

Build SpiderMonkey
------------------

1. Download SpiderMonkey 1.7.0 from ftp://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz
2. Extract js folder into the same directory you will be placing the
MongoDB source folder later.
3. Copy the contents of http://github.com/mongodb/mongo-snippets/blob/master/jslib-sconstruct
into the file js/src/SConstruct
3. From the Visual Studio Command Prompt, change to the js/src
directory and execute:
set CFLAGS="-DJS_C_STRINGS_ARE_UTF8"
scons

Official instructions - http://www.mongodb.org/display/DOCS/Building+Spider+Monkey

Build MongoDB C++ Client Driver
-------------------------------

1. Download MongoDB source from http://www.mongodb.org/downloads
2. Extract contents into the same directory that you extracted the
SpiderMonkey js folder.
3. Modify MongoDB's main SConstruct file to build with the runtime
library you will be using. This step was the main solution to fixing
release build linker errors in my application. In my case, our release
builds use the Multi-threaded DLL (/MD) runtime library switch.
However, the client driver uses Multi-threaded (/MT), which is strange
considering their debug version uses Multi-threaded Debug DLL (/MDd)
and not Multi-threaded Debug (/MTd). So a simple search and replace of
the release build switch from /MT to /MD solved my issues.
4. From the Visual Studio Command Prompt, change to the mongodb
source directory
a. Execute "scons mongoclient" for a debug build of
mongoclient.lib
b. Execute "scons --release mongoclient" for a release build of
mongoclient.lib

Official instructions - http://www.mongodb.org/display/DOCS/Building+with+Visual+Studio+2008

Integrating with VS 2008 Application
------------------------------------

1. Add Boost and MongoDB to your project's include paths at "C/C++ ->
General -> Additional Include Directories"
2. Add Boost and MongoDB to your project's library paths at "Linker -
> General -> Additional Library Directories"
3. Add wsock32.lib and mongoclient.lib to "Linker -> Input"
a. Make sure to use the appropriate debug/release version of
mongoclient.lib
4. Add "#include <mongo/client/dbclient.h>" to your code
5. Use the client driver, compile, and run!

Official instructions - http://www.mongodb.org/pages/viewpage.action?pageId=133415

-------------------------------------

Most of this is taken straight from the official instructions off
mongodb.org, but a lot of trial and error was needed to find step 3 in
"Building MongoDB C++ Client Driver". Step 3 in "Integrating with VS
2008 Application" also took some searching to learn that wsock32.lib
is explicitly needed. I hope these instructions help others avoid the
pitfalls and frustrations I experienced.

It amazes me how many steps are required. I know mongodb.org provides
some pre-built libraries, but I never could seem to get them to work,
and opted for the brute force method. Maybe after discovering the
runtime library switch issue, I could cut down on some of the build
steps.
Reply all
Reply to author
Forward
0 new messages