使用VS2010编译MongoDB的c++ client

来源:互联网 发布:关于网络的作文 编辑:程序博客网 时间:2024/06/08 17:43

使用VS2010编译MongoDB的c++ client

1.编译boost

boost库下载地址 http://www.boost.org/users/history/;
mongodb2.1及以上版本采用boost_1_49_0,更早的mongodb版本采用boost_1_42_0。下载需要的版本库并解压。

以下命令行操作均在 Visual Studio 命令提示(2010) 下进行

(1)生成bjam: 

cd E:\MONGODB\boost_1_49_0\tools\build\v2\engine  或者 cd E:\MONGODB\boost_1_42_0\tools\jam\src   (不同的boost版本目录有所不同)

build 

window下会自动调用cl编译 

对应生成的 bjam.exe 在 E:\MONGODB\boost_1_49_0\tools\build\v2\engine\bin.ntx86 或 E:\MONGODB\boost_1_42_0\tools\jam\src\bin.ntx86


(2)编译需要的boost库 
拷贝bjam.exe到boost文件夹根目录,执行 
E:\MONGODB\boost_1_49_0>bjam variant=release --with-filesystem --with-thread --with-date_time --with-program_options threading=multi toolset=msvc-10.0 link=static runtime-link=static address-model=64 
此处为MongoDB文档中对于编译boost库的要求原文: 
When using bjam, MongoDB expects 
variant=debug for debug builds, and variant=release for release builds 
threading=multi 
link=static runtime-link=static for release builds 
address-model=64 for 64 bit 

link=static runtime-link=static,boost需要编译成静态库,因为mongodb只会去链接boost的静态库 
address-model=64在win7 64环境下此项必须,不加在编译mongodb的c++ client时会出现链接错误。 

生成的 libboost*.lib 在 E:\MONGODB\boost_1_49_0\bin.v2\libs  或  E:\MONGODB\boost_1_42_0\bin.v2\libs ,搜索*.lib 即可。

2.编译mongoclient.lib

(1)搭建编译环境

下载安装 python-2.7.3.msi 和 scons-2.2.0-setup.exe ,先装python,再装scons。

添加 C:\Python27\Scripts 到系统路径。

(2)编译mongo

下载mongodb c++ driver 源码,下载地址 http://www.mongodb.org/downloads;(注意:要点击相应版本下的 SOURCE TGZ | ZIP 连接)

解压后执行以下命令

cd E:\MONGODB\mongodb-src-r2.5.1

scons --release --64 mongoclient.lib   (64位release版本)

scons --dd --64 mongoclient.lib   (64位debug版本)

注意:有的低版本的mongo源码不包含boost源码,

原创粉丝点击