【MongoDB实战经验四】:Mongo-CXX-Driver 3.4版本编译

Mongo-CXX-Driver 3.4版本编译

一.环境准备

1.安装 【cmake 3.15.1】

【cmake 3.15.1】官网下载地址:

https://cmake.org/download/

2.安装VS2015

本示例安装的VS2015为update 3版本

3.安装boost

【boost 1.70.0】官网下载:

https://dl.bintray.com/boostorg/release/1.70.0/binaries/

4.下载【mongo-c-driver-1.14.0】和【mongo-cxx-driver-r3.4.0】

【mongo-c-driver-1.14.0】官网下载地址:
https://codeload.github.com/mongodb/mongo-c-driver/zip/1.14.0

【mongo-cxx-driver-r3.4.0】官网下载地址:
https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.4.0.zip

二.编译步骤

官网说明:
bson和mongoc编译官方指导 http://mongoc.org/libmongoc/current/installing.html

mongocxx编译官方指导:http://mongocxx.org/mongocxx-v3/installation/

1.目录结构整理

下载的文件
D:\mongo-3.4\mongo-c-driver-1.14.0.tar.gz
D:\mongo-3.4\mongo-cxx-driver-r3.4.0.zip

解压后的
D:\mongo-3.4\mongo-c-driver-1.14.0\
D:\mongo-3.4\mongo-cxx-driver-r3.4.0\

新建的编译脚本文件
D:\mongo-3.4\Build—step1.bat
D:\mongo-3.4\Build—step1.bat
D:\mongo-3.4\Build—step3.bat
D:\mongo-3.4\Build—step4.bat

脚本生成的文件夹
D:\mongo-3.4\mongo-c-driver

2.构建bson和mongoc

1)将【mongo-c-driver-1.14.0】进行解压

2)新建文本文件 【Build——step1.bat】,编辑内容如下:
	cd mongo-c-driver-1.14.0
	mkdir cmake-build
	cd cmake-build
	cmake -G "Visual Studio 14 2015" -A Win32 
	cmake -LH ..
	pause
3)双击2)中新建的bat文件

执行完成后,将在cmake-build文件夹中生成【ALL_BUILD.vcxproj】和【INSTALL.vcxproj】工程文件

备注:此处需要保证 环境变量path中存在cmake的目录,示例中cmake的目录为【C:\Program Files\CMake\bin】,否则会提示cmake不是命令;cmake -LH ..表示采用默认参数构建

3.编译bson和mongoc

1)新建文本文件【Build-step2.bat】,编辑内容如下:

cd mongo-c-driver-1.14.0\cmake-build
MSBuild.exe /p:Configuration=Release ALL_BUILD.vcxproj
pause

2)新建文本文件【Build—step3.bat】,编辑内容如下:
cd C:\Users\liufen\Desktop\mongo-3.4\mongo-c-driver-1.14.0\cmake-build
MSBuild.exe /p:Configuration=Release INSTALL.vcxproj
pause

3)采用管机员方式打开【命令提示符】,将路径调整为【D:Mongondb3.4】,然后将1)中的【Build——step2.bat】内容拷贝到【命令提示符】中

4)采用管机员方式打开【命令提示符】,将路径调整为【D:Mongondb3.4】,然后将1)中的【Build——step3.bat】内容拷贝到【命令提示符】中

备注1:此处需要确保系统环境变量path中包含msbuild的目录,示例中msbuild的目录为【】

备注2:之所以不能直接运行1)和2)中的bat文件,是因为在【构建Libbson和lobmongoc】时,采用的是默认的采用构建,默认最后的编译结果会放到【C:\Program Files (x86)\mongo-c-driver】中。

5)将编译后的结果拷贝到当前目录,新建文本文件【Build-step4.bat】,编辑内容如下:

echo 将【C:\Program Files (x86)\mongo-c-driver】拷贝到当前目录中
mkdir mongo-c-driver
XCOPY "C:\Program Files (x86)\mongo-c-driver" D:\mongo-3.4\mongo-c-driver /S /E /Y
pause

4.编译mongocxx

1)采用cmake gui工具进行构建

	设置source code path 为  D:/mongo-3.4/mongo-cxx-driver-r3.4.0
	设置build path 为 D:/mongo-3.4/mongo-cxx-driver-r3.4.0/cmake-build
    设置编译平台是  VS2015 14 win32
	新增参数 CMAKE_PREFIX_PATH 为 D:/mongo-3.4/mongo-c-driver
            BOOST_ROOT=C:\local\boost_1_70.0
            CMAKE_CXX_FLAGS="/Zc:__cplusplus"

2)编译mongocxx并将编译后的结果拷贝到【mongo-cxx-driver】

	cd mongo-cxx-driver-r3.4.0\cmake-build
	MSBuild.exe /p:Configuration=Release ALL_BUILD.vcxproj
	MSBuild.exe /p:Configuration=Release INSTALL.vcxproj
	
	echo 将【D:\mongo-3.4\mongo-cxx-driver-r3.4.0\cmake-build\install】拷贝到当前目录中
	mkdir mongo-cxx-driver
	xcopy "D:\mongo-3.4\mongo-cxx-driver-r3.4.0\cmake-build\install" D:\mongo-3.4\mongo-cxx-driver /S /E /Y
	pause
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值