在 Windows7、64x、VS2010环境下安装C++ driver/mongoDB并配置的具体实现

时间:2022-09-12 11:08:34

NoSQL最近很火,非关系型、分布式是它的设计思想,Mongodb是NoSQL的领导者,

它是一种基于文档的key-value形式的非关系型数据库。主要用于非结构化的大数据和云计算上。

鉴于MongoDB这么前沿,我也想研究一下,还可能以后用在项目上。

在折腾了几天后,终于成功的安装和配置了vs2010环境下的C++ driver/mongoDB。

网上的资料太多,让人眼花缭乱,并且,很多都不能编译成功,要么是缺少一些文件,

要么是编译出错,搞得我头大,功夫不负有心人,后来,终于看到了How I installed the Windows 7 64x C++ driver/mongoDB to work with Visual Studio 2010,使我将开发环境配置成功。以下是原文,英文看起来很容易,就不翻译了。

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

I realize this is way to explicit for most but I did not want to leave out

any ingredients for this recipe. I put this together with the help of Tad
Marshall and Erik Milke without whom I would still be at sea. Thanks!

This guides assumes you are starting with a blank slate (except for MS
Visual Studio 2010). In particular it assumes:

- Python is not installed. If Python 64 bit or a version later than 2.72
is installed, you may have a problem with scons which is 32 bit and
requires 2.72 Python.
- scons is not installed.
- Boost is not installed.
- Mongodb is not installed, binaries or otherwise. We are starting from
scratch.
- You are using Windows 7 x64 and Microsoft Visual Studio 2010 and want
the x64 version of mongoDB
- You want the debug version of mongoDB. I've not tried this for a
release version.
- You will be using the debug C runtime external DLLs msvcr100d.dll
and msvcp100d.dll vs. including the code itself. See the note at the very
end.

This is not the only possible avenue; building with MS VS 2010, building
boost with bjam are alternatives, etc. But this is the way I was able to
successfully install.
----------------------------------------------------------------------------------------------------------------------------------------
*Install Python *

0. **VERY IMPORTANT**: Get the 32 bit NOT the 64 bit version. Scons uses 32
bit Python.

1.  http://www.python.org/download/releases/2.7.2/

2. Select Windows x86 MSI Installer (2.7.2) (sig)

3. You will end up with:

python-2.7.2.msi

4. Double click the installer. Install in C:\Python27\, accept all other
defaults

5. Add the python scripts directory (e.g., C:\Python27\Scripts) to your
PATH.

Start->Control panel->System->Advanced system settings->Environmental
variables

Select PATH in the top box "User variables for _____"
Click Edit.
Add ";C:\Python27\Scripts" to the end of the PATH variable -- the
semi-colon separates values.
Click OK, OK, OK

Be sure to restart any command prompt to get the new PATH.
----------------------------------------------------------------------------------------------------------------------------------------
*Install pywin32*

1. Download
http://sourceforge.net/projects/pywin32/files/pywin32/Build216/pywin32-216.win32-py2.7.exe/download

2. You will end up with:

pywin32-216.win32-py2.7.exe

3. Double click. Accept all the defaults
----------------------------------------------------------------------------------------------------------------------------------------
*Install scons*

1. Download:


http://sourceforge.net/projects/scons/files/scons/2.1.0/scons-2.1.0.win32.exe/download

2. You will get:

scons-2.1.0.win32.exe

3. Double click. Accept all the defaults
----------------------------------------------------------------------------------------------------------------------------------------
*Download and unpack mongodb source*

1.  http://www.mongodb.org/downloads

2. Download source -- far right column, click the "zip" link. I chose the
production release 2.0.7 -- if you use another, then your YMMV. I know that
they have included boost in later distributions but if you want to follow
this plan, stick with 2.07. This will give you:

mongodb-src-r2.0.7.zip

3. Unpack it to to C:\ so you have a directory named:

C:\mongodb-src-r2.0.7

4. Rename c:\mongodb-src-r2.0.7 to C:\mongodb
----------------------------------------------------------------------------------------------------------------------------------------
*Install boost*

1. Get boost 1.4.2 from:

http://www.boost.org/users/history/

which will get you:

mongodb-src-r2.0.7.tar.gz.tar

I'm using WinRar, so when I double click on
mongodb-src-r2.0.7.tar.gz.tar I get:

boost_1_42_0-1.7z

*Don't get 1.45 or later!* According to:


http://www.mongodb.org/display/DOCS/Boost+and+Windows#BoostandWindows-BuildingYourself

"We have successfully compiled version 1.42 – you might want to try that
version or higher, but not 1.45 or later. 1.45 changed the interface to the
boost::filesystem library and we've yet to catch up."
I decided to stick with 1.4.2.

2. Unpack boost_1_42_0-1.7z to your C:\ drive so you have a directory
called:

C:\boost_1_42_0-1

3. Rename C:\boost_1_42_0-1.7z to c:\boost

4. Run MS Visual Studio 64x command prompt:

Start->All Programs->Microsoft Visual Studio 2010->Visual Studio Tools->
Visual Studio x64 Win64 Command Prompt (2010)

5. cd C:\Program Files (x86)\Microsoft Visual Studio 10.0\vc\

6. vcvarsall.bat

7. cd c:\boost\tools\jam\src

8. build.bat

9. mkdir c:\boost\bin

10. mkdir c:\boost\lib

11. copy C:\boost\tools\jam\src\bin.ntx86\bjam.exe c:\boost\bin

12. Steps 7 through 11 are requirements for building boost with mongodb's
buildscript (see step 14). If you skip them, it won't run (for instance,
the script assumes c:\boost\lib already exists).

13. cd c:\mongodb\buildscripts

14. buildboost64.bat

Press Enter at the four prompts.
----------------------------------------------------------------------------------------------------------------------------------------
*Build mongoDb, client and core*

0. Working in the same MS Visual Studio 64x command prompt:

1. cd c:\mongodb

2. scons --64

3. scons --dd --64 mongoclient.lib

4. scons --dd --64 core
----------------------------------------------------------------------------------------------------------------------------------------
*Setup Microsoft Visual Studio 2010*

1. Create new project.

2. Properties: Click Configuration Manager

3. Click the Active Solution Platform list, and then select the <New…>
option to open the New Solution Platform Dialog Box.

4. Select the new platform drop-down arrow, and then select x64.

5. OK, Close, OK.

6. Other properties:

Properties: Configuration Properties->Linker->Input->Additional
Dependencies add:

ws2_32.lib
"C:\mongodb\mongoclient.lib"

Properties: Configuration Properties->vc++ Directories->Include
Directories add:

c:\mongodb
c:\boost

Properties: Configuration Properties->Linker->General->Additional
Library Directories add:

C:\boost\lib
C:\mongo

Properties: Configuration Properties-> C/C++->Code Generation
select:

/MDd

Properties: Configuration Properties --> C/C++ ->
Preprocessor->Precprocessor Definitions add:

_CRT_SECURE_NO_WARNINGS

Properties: Configuration Properties --> C/C++ -> Advanced ->
Disable Specific Warnings

4267
----------------------------------------------------------------------------------------------------------------------------------------
*Have fun. *

*Note*: I'm using /MDd vs. /MTd because I was struggling with linking to
the correct version of the boost library. I kept getting errors such as:

LNK1104: cannot open file 'libboost_thread-vc100-mt-sgd-1_42.lib'


Tad Marshall explained:

This variant is for statically linking against the C runtime library. You
can either tell Visual Studio to use the debug DLL version of the library
(which will use your -gd- version) or build the -sgd- version yourself. If
you build the complete set of Boost libraries it should include this one.
The code will be built to (for example) C:\boost_1_42_0\bin.v2\libs\
thread\build\msvc-10.0\debug\link-static\runtime-link-static\threading-multi\libboost_thread-vc100-mt-sgd-1_42.lib
and will be copied to C:\boost_1_42_0\stage\lib. You can pass a set of
options on the command line to Boost's bjam.exe to build just the specific
variant that you need; see
http://www.boost.org/doc/libs/1_42_0/more/getting_started/windows.html#library-namingfor details. Ordinarily, you could download pre-built libraries from
http://www.boostpro.com/download/ , but for Boost version 1.42 they don't
have a Visual Studio 2010 set, so for 1.42 and VC 10.0 you need to build
your own.
So, to use the debug DLL version of the library, Tad again explained:

"To use the debug DLL version of the library, [use] "Multi-threaded Debug


转:http://grokbase.com/t/gg/mongodb-user/128tmfjfdj/how-i-installed-the-windows-7-64x-c-driver-mongodb-to-work-with-visual-studio-2010

REF:http://blog.csdn.net/frogjason/article/details/8160472