win下编译、安装mongo-cxx-driver-legacy

首先编译boost,版本选的是1.55

bootstrap.bat

.\b2 --build-type=complete  install threading=multi    (完整编译)

然后编译mongo-cxx-driver-legacy,在vs2013的VS2013 x86 Native Tools Command Prompt命令行下

scons --32 --prefix="C:\mongo-client-install" --cpppath="C:\Boost\include\boost-1_55" --libpath="C:\Boost\lib" install 
scons --32 --prefix="C:\mongo-client-install" --cpppath="C:\Boost\include\boost-1_55" --libpath="C:\Boost\lib" install --dbg=on
scons --32 --prefix="C:\mongo-client-install" --cpppath="C:\Boost\include\boost-1_55" --libpath="C:\Boost\lib" install --dynamic-windows --sharedclient
scons --32 --prefix="C:\mongo-client-install" --cpppath="C:\Boost\include\boost-1_55" --libpath="C:\Boost\lib" install --dynamic-windows --sharedclient --dbg=on

编译生成的lib和头文件放在C:\mongo-client-install下,如图所示

win下编译、安装mongo-cxx-driver-legacy_第1张图片


然后设置工程配置:


将下面的dll拷贝到exe目录就可以了:

win下编译、安装mongo-cxx-driver-legacy_第2张图片


测试程序如下所示:

#include "stdafx.h"
#include
#include
#include
#include
#include // for the driver
#pragma comment(lib, "ws2_32.lib")

void run() {
    mongo::DBClientConnection c;
    c.connect("localhost");
}


int main(int , char **) {
   mongo::client::initialize();
    try {
        run();
        std::cout << "connected ok" << std::endl;
    }
    catch (const mongo::DBException &e) {
        std::cout << "caught " << e.what() << std::endl;
    }
    return EXIT_SUCCESS;
}




你可能感兴趣的:(win下编译、安装mongo-cxx-driver-legacy)