C++ driver

312 views
Skip to first unread message

elgcom

unread,
Jun 9, 2012, 6:04:33 AM6/9/12
to mongodb-user
My setup:
Windows XP x86
Visual Studio 2010 Express
Python2.7
Scons 2.1
Boost 1.47 binary dist from http://www.boostpro.com/download/
mongoDB win32-i386-2.0.6-rc0


I downloaded cxx-driver/mongodb-linux-x86_64-2.1.1.tgz from
http://dl.mongodb.org/dl/cxx-driver/ and built it successfully with
some effort (e.g. adding boost dependencies, defining UNICODE in
SConstruct..)

The build process of c++ driver looks like this:
============= Build driver OK ==========================
....
timer.cpp
cl /Fobuild\mongo\util\trace.obj /c src\mongo\util\trace.cpp /TP /
nologo /EHsc /
O2 /D_SCONS /DMONGO_EXPOSE_MACROS /D_UNICODE /DUNICODE /Ibuild /Isrc /
Ibuild\mon
go /Isrc\mongo "/IC:\Program Files\boost\boost_1_47\include" "/IC:
\Program Files
\boost\boost_1_47"
....
Install file: "build\mongoclient.lib" as "mongoclient.lib"
scons: done building targets.
====================================================

Then I try to write my first test in VC10 Express but I got the
strange error.
============== Build client test failed =====================
1>mongoclient.lib(dbclient.obj) : error LNK2038: mismatch detected for
'_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in
MyApp.obj
.....
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __thiscall
std::_Container_base12::~_Container_base12(void)" (??
1_Container_base12@std@@QAE@XZ) already defined in
mongoclient.lib(dbclient.obj)
.....
1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of
other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of
other libs; use /NODEFAULTLIB:library
1>mongoclient.lib(sock.obj) : error LNK2019: unresolved external
symbol __imp__inet_addr@4 referenced in function
_WspiapiParseV4Address@8
....
===================================================

My VC 10 Express project setting looks something like this
=============== MyApp.vcxproj ========================
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://
schemas.microsoft.com/developer/msbuild/2003">
....

<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;%
(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>\path\to\mongo-cxx-
driver-2.1.1\build</AdditionalLibraryDirectories>
<AdditionalDependencies>mongoclient.lib;boost_thread-vc100-
mt-1_47.lib;boost_filesystem-vc100-
mt-1_47.lib;libboost_program_options-vc100-mt-1_47.lib</
AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$
(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>\path\to\mongo-cxx-
driver-2.1.1\src;\path\yo\mongo-cxx-driver-2.1.1\src\mongo;%
(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
........
</Project>
==================================================

thanks a lot for any help :P

Best Regards

elgcom

unread,
Jun 9, 2012, 11:05:23 AM6/9/12
to mongod...@googlegroups.com
Somehow I have a successful build finally.
Here I would like to show what I have done and hope it could help someone who is also struggling with C++ driver.


My setup: 
Windows XP x86 
Visual Studio 2010 Express 
Python2.7 
Scons 2.1 
Boost 1.42 binary dist from http://www.boostpro.com/download/ 
mongoDB win32-i386-2.0.6-rc0  

Note: It may have problems with Boost 1.47
 
1) Since boostpro privides Boost distribution only for VC9 or less, I downloaded boost_1_42_vs2010_partial_prebuilt.7z from http://www.mongodb.org/pages/viewpageattachments.action?pageId=12157032 and unpack the *.lib to the directory c:\program files\boost\boost_1_42 which is the default installation location of boostpro's Boost distribution.

2) I compile c++ client directly from the mongoDB source (the same version that I use as server, i.e. 2.0.6-rc0)
   * use VC 2010 Express Command Prompt
   * execute "scons mongoclient" under  mongoDB source folder where a SConstruct file is located.
   After that you wlll have "mongoclient.lib" built.

3) Now, write client test code in VC 2010 Express. I use the example under mongo source folder (e.g. client/examples), but not the examples on tutorial web pages....
   In VC 2010 Express you need to have some setup
   * C/C++ -> General -> Additional Include Directories: boost folder and mongoDB source folders (e.g. c:\program files\boost\boost_1_42 and c:\path\to\mongodb_src)
   * C/C++ -> Preprocessor-> Preprocessor Definitions: _CRT_SECURE_NO_WARNINGS, _UNICODE, UNICODE
   * Linker -> General ->Additional Library Directories: boost lib and mongoclient lib (e.g. c:\program files\boost\boost_1_42\lib and c:\path\to\built_mongoclient_lib)
   * Linker -> Input -> Additional Dependencies: ws2_32.libmongoclient.lib

It should work now :p
Reply all
Reply to author
Forward
0 new messages