C++ drivers for Windows problem (Visual Studio C++ 2010)

341 views
Skip to first unread message

noizex

unread,
Feb 26, 2012, 7:15:40 AM2/26/12
to mongodb-user
Hello,

I tried everything now for few hours and I didnt have any luck
compiling mongodb libraries to use with C++ project. It seems so much
more complex than any library I used so far (and I used a few..) that
I can't really find a solution to my problem.

I tried two ways - compiling from VC2010 solution
(mongo_client_lib.cpp) and compiling with scons - both ways yielded
very different library files (VS2010 version was 21MB and scons was
140MB - btw where does such a big difference come from?). After adding
library path and .lib file to my project I get following linking
error:

1>LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc100-
mt-1_42.lib'

This error appears with both libraries (obtained from VS2010 and
scons). Its my first library that depends so heavily on boost, till
now I avoided this juggernaut of libraries and was happy,
unfortunately MongoDB is first library I really want to use that uses
it :( Why adding library to my project adds such dependency on boost
libraries? And why does it ask for 'libboost_thread-vc100-mt-1_42.lib'
file, while Boost files I downloaded from Mongo site are 'libboost_*-
vc100-mt-gd-1_42' and 'libboost_*-vc100-mt-s-1_42'?

I really have no idea what to do, should I also link these boost files
to my project? And why scons version takes 140MB and yet it still asks
for some external libraries? I'm not experienced in C++ libraries, I'm
a simple user, I add library and headers and use it in my project, and
I really want to use MongoDB but this is just too much for me.

Any help greatly appreciated.

K.

Tad Marshall

unread,
Feb 26, 2012, 11:00:58 AM2/26/12
to mongodb-user
Sorry you're having such difficulty. We know that there are problems
building with the C++ driver and we're trying to make it better.

If you aren't building from our very latest source code, this will be
harder. If you haven't done this already, you should probably clone
the Git archive onto your build machine. This is mostly because a lot
of scons work has gone on in the last few months.

I think that scons is building full debugging information directly
into the .lib file while the Visual Studio solution file is creating a
separate .pdb file, and that is why you are seeing the huge difference
in size.

The boost libraries are very sensitive to the exact compiling and
linking options you are using, and the file name of the Boost library
indicates exactly what that library was built for. This means that a
particular prebuilt Boost library requires your compile options to be
exactly what that library was built for. The online Boost
documentation has information on the naming convention they use, but
if you don't live and breathe Windows compiling and linking in the
Visual Studio environment you will find it rather hard to read.

In order to give myself additional flexibility in choosing my own
compile and link options (debug versus release, static versus dynamic
linking) I just built every Boost library variation from the source
code. It sounds nasty, but it's actually fairly well documented and
automated and it doesn't take too horrible an amount of time ... under
an hour on a fast machine. My "for building MongoDB" Boost universe
(C:\boost) including source code and all libraries used by MongoDB (32-
bit and 64-bit) is about 175 MB on disk. But the FULL build I did
takes more like 10 GB. Look at http://www.boost.org/doc/libs/1_46_1/more/getting_started/windows.html
for more information, and skip down to "5.2 Or, Simplified Build
From Source" for a possible starting point.

Looking in my build source tree, I found the file libboost_thread-
vc100-mt-1_42.lib in a directory named G:\boost_1_42_0\bin.v2\libs
\thread\build\msvc-10.0\release\link-static\threading-multi . This
suggests that you are trying to create a release build by statically
linking in the multi-threaded libraries. The files you mentioned
downloading (inserting "thread" for "*" in libboost_*-vc100-mt-gd-1_42
and libboost_*-vc100-mt-s-1_42) are in G:\boost_1_42_0\bin.v2\libs
\thread\build\msvc-10.0\debug\link-static\threading-multi (for
libboost_*-vc100-mt-gd-1_42) and G:\boost_1_42_0\bin.v2\libs\thread
\build\msvc-10.0\release\link-static\runtime-link-static\threading-
multi (for libboost_thread-vc100-mt-s-1_42.lib).

I'm sorry this is so hard. You might want to try downloading a
prebuilt set of libraries from the Boost site, or you could try
changing you link settings to match the libraries you have.

If all else fails, I can e-mail you the set of Boost libraries that I
use (and that I built myself). The 32-bit set is about 3 MB
compressed with 7-zip, the 64-bit 7-zip file is a bit over 4 MB.

Good luck, and let us know how it goes!

Tad

noizex

unread,
Feb 27, 2012, 11:20:55 AM2/27/12
to mongodb-user
Hello,

First, thanks for very detailed reply and taking time to investigate
my problem, greatly appreciated :) After your post and additional hour
spent on trying different scenarios, I renamed libraries I had to ones
that were expected by the linked mongoclient.lib and it acutally
worked. It seems that these "-gd-" "-s-" libraries are from debug
then, and the ones that were expected are in release directory - I
just downloaded pre-made Boost from Mongo site so I didn't even know
what its all about, and I wasn't familiar with their naming convention
too.

Once I did it, my application stopped complaining about missing boost
libs, but started throwing "redefined.." errors on various libraries I
used. I googled a bit and found people having these problems, without
solution though. The fix was to use /MT (or similar, can't remember
today) switch when compiling my own application - after doing this it
started to compile just fine.

I already wrote some code for my server and Mongo behaves correctly
filled with data from C++ so it seems to be okay now :)

Thanks once again for help! I'm so relieved now. Of course, as you
said it would be really good to make this a bit more straightforward
so people don't have to go through this frustrating process, and maybe
drop in the middle without figuring it out, but at least its something
that can be solved with a bit of time invested.

K.
> takes more like 10 GB. Look athttp://www.boost.org/doc/libs/1_46_1/more/getting_started/windows.html

kolobok

unread,
May 5, 2012, 4:05:52 PM5/5/12
to mongod...@googlegroups.com
scons: done reading SConscript files.
scons: Building targets ...
cl /Foclient\examples\authTest.obj /c client\examples\authTest.cpp /TP /nologo /D_SCONS /DMONGO_EXPOSE_MACROS /Imon
go
authTest.cpp
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\xlocale(342) : warning C4530: Использован обработчик исключ
ений C++, но семантика уничтожения объектов не включена. Задайте параметр /EHsc
c:\mongo-cxx-driver-v2.0\mongo\client\../pch.h(80) : fatal error C1083: Не удается открыть файл include: boost/thre
ad/once.hpp: No such file or directory
scons: *** [client\examples\authTest.obj] Error 2
scons: building terminated because of errors.

Tad Marshall

unread,
May 5, 2012, 5:06:34 PM5/5/12
to mongod...@googlegroups.com
What version of the MongoDB source code are you using?

What command are you using to build?  Can you post the entire thing ... your command line and all output?

If you are building an older version (not the latest from GitHub), do you have boost installed?

The current code (2.0 and newer) expects Visual Studio 2010.  I doubt that that is the source of your build errors, but it could cause issues later.  The warning about /EHsc could be coming from that, if the default for C++ exceptions changed.  MongoDB code requires that C++ exceptions be enabled.
Reply all
Reply to author
Forward
0 new messages