参考来源:
https://github.com/mongodb/mongo-cxx-driver/wiki/Download-and-Compile-the-Legacy-Driver#building-on-windows
http://m.blog.csdn.net/blog/nwzhourui/48289047
http://blog.csdn.net/aslucky/article/details/47663803
打开Developer Command Prompt for VS2015命令行窗口
在目录 D:\boost_1_59_0 下面执行bootstrap, 然后编译成64位:
bjam --toolset=msvc-14.0 address-model=64 --build-type=complete stage
6.
下载mongo-cxx-driver-legacy,地址:https://github.com/mongodb/mongo-cxx-driver.git,解压到 D:\mongo_drive 下
在 CMD 窗口中, 进入目录 D:\mongo_drive\mongo-cxx-driver-legacy, 然后执行下面的命令
scons --64 --sharedclient --dynamic-windows --prefix="d:\mongo_drive" --cpppath="D:\boost_1_59_0" --libpath="d:\mongo_drive\boost_lib" install
现在在 d:\mongo_drive 下生成了两个文件夹 lib 和 include,就是 mongodb C++ 驱动
8.
测试 MONGODB 驱动
创建一个 cpp 文件, 写入下面代码, 并 选用 release 模式编译链接
#include <iostream>
#include <winsock2.h>
#include "d:/mongo_drive/include/mongo/client/dbclient.h"
mongo::DBClientConnection oDB;
void main()
{
mongo::client::initialize();
char szRemoteAddr[30];
sprintf(szRemoteAddr, "%s:%d", "192.168.56.3", 27017);
try
{
oDB.connect( szRemoteAddr );
std::cout << "connect succ" << std::endl;
}
catch (const mongo::DBException &e) {
std::cout << "caught " << e.what() << std::endl;
}
mongo::client::shutdown();
}
9.
项目中需要包含库目录地址,在项目属性 - C/C++目录 - 常规 选项页中,附加包含目录添加
d:/mongo_drive/include/mongo;d:/boost_1_59_0;d:/mongo_drive/include
在项目属性 - 链接器 - 常规 选项页中,附加库目录添加
d:/mongo_drive/lib 和 d:/boost_1_59_0/boost_lib,
在项目属性 - 链接器 - 输入选项页中, 附加依赖项添加
ws2_32.lib;mongoclient.lib
boost_chrono-vc140-mt-gd-1_59.dll
boost_container-vc140-mt-1_59.dll
boost_container-vc140-mt-gd-1_59.dll
boost_date_time-vc140-mt-1_59.dll
boost_date_time-vc140-mt-gd-1_59.dll
boost_regex-vc140-mt-1_59.dll
boost_regex-vc140-mt-gd-1_59.dll
boost_system-vc140-mt-1_59.dll
boost_system-vc140-mt-gd-1_59.dll
boost_thread-vc140-mt-1_59.dll
boost_thread-vc140-mt-gd-1_59.dll
=============================================================================================
大功告成, 第 8 步代码编译链接通过并成功运行
https://github.com/mongodb/mongo-cxx-driver/wiki/Download-and-Compile-the-Legacy-Driver#building-on-windows
http://m.blog.csdn.net/blog/nwzhourui/48289047
http://blog.csdn.net/aslucky/article/details/47663803
1.
编译 boost,使用 boost 1.59 版本。之前使用 boost 1.55,但使用 VS2015 总是编译不通过, 换成 boost 1.59 就没问题了
打开Developer Command Prompt for VS2015命令行窗口
在目录 D:\boost_1_59_0 下面执行bootstrap, 然后编译成64位:
bjam --toolset=msvc-14.0 address-model=64 --build-type=complete stage
2.
安装 python2.7
3.
创建目录 d:\mongo_drive
4.
从 http://sourceforge.net/projects/scons/files/scons/2.4.0/ 下载 scons包到 d:\mongo_drive
打开 CMD 窗口, 运行 python setup.py install 来安装 scons
5.
创建目录 d:\mongo_drive\boost_lib, 把 D:\boost_1_59_0\bin.v2 目录下的所有 lib 文件( 搜索出来并 )拷贝过去
6.
下载mongo-cxx-driver-legacy,地址:https://github.com/mongodb/mongo-cxx-driver.git,解压到 D:\mongo_drive 下
在 CMD 窗口中, 进入目录 D:\mongo_drive\mongo-cxx-driver-legacy, 然后执行下面的命令
scons --64 --sharedclient --dynamic-windows --prefix="d:\mongo_drive" --cpppath="D:\boost_1_59_0" --libpath="d:\mongo_drive\boost_lib" install
scons --64 --sharedclient --dynamic-windows --prefix="d:\mongo_drive" --cpppath="D:\boost_1_59_0" --libpath="d:\mongo_drive\boost_lib" install --dbg=on
现在在 d:\mongo_drive 下生成了两个文件夹 lib 和 include,就是 mongodb C++ 驱动
8.
测试 MONGODB 驱动
创建一个 cpp 文件, 写入下面代码, 并 选用 release 模式编译链接
#include <iostream>
#include <winsock2.h>
#include "d:/mongo_drive/include/mongo/client/dbclient.h"
mongo::DBClientConnection oDB;
void main()
{
mongo::client::initialize();
char szRemoteAddr[30];
sprintf(szRemoteAddr, "%s:%d", "192.168.56.3", 27017);
try
{
oDB.connect( szRemoteAddr );
std::cout << "connect succ" << std::endl;
}
catch (const mongo::DBException &e) {
std::cout << "caught " << e.what() << std::endl;
}
mongo::client::shutdown();
}
9.
项目中需要包含库目录地址,在项目属性 - C/C++目录 - 常规 选项页中,附加包含目录添加
d:/mongo_drive/include/mongo;d:/boost_1_59_0;d:/mongo_drive/include
在项目属性 - 链接器 - 常规 选项页中,附加库目录添加
d:/mongo_drive/lib 和 d:/boost_1_59_0/boost_lib,
在项目属性 - 链接器 - 输入选项页中, 附加依赖项添加
ws2_32.lib;mongoclient.lib
把 d:\mongo_drive\lib 目录下的 mongoclient.dll , mongoclient-gd.dll 拷贝到程序执行目录
把下面几个 dll 文件在 D:\boost_1_59_0\bin.v2 目录下( 搜索出来并 )拷贝到程序执行目录
boost_chrono-vc140-mt-1_59.dllboost_chrono-vc140-mt-gd-1_59.dll
boost_container-vc140-mt-1_59.dll
boost_container-vc140-mt-gd-1_59.dll
boost_date_time-vc140-mt-1_59.dll
boost_date_time-vc140-mt-gd-1_59.dll
boost_regex-vc140-mt-1_59.dll
boost_regex-vc140-mt-gd-1_59.dll
boost_system-vc140-mt-1_59.dll
boost_system-vc140-mt-gd-1_59.dll
boost_thread-vc140-mt-1_59.dll
boost_thread-vc140-mt-gd-1_59.dll
=============================================================================================
大功告成, 第 8 步代码编译链接通过并成功运行