有朋友问如何编译 mondb_fdw 的Windows版,本文是准备依赖包的过程。html
一、下载Windows版CMakegit
网址:https://cmake.org/download/github
下载zip包便可,咱们能够手动在命令行设置path,不必用安装程序。mongodb
当前版本 3.15.3,解压到 C:\cmake-3.15.3-win64-x64。json
二、下载MongoDB C Driverui
网址:http://mongoc.org/命令行
当前版本 1.15.1,解压至 C:\mongo-c-driver-1.15.1code
(Windows下解压 tar 文件可以使用 7-zip)htm
三、微调代码ip
src/libbson/src/bson/bson-macros.h
这里的内存对齐在Windows下有点问题,粗暴地注释掉
#ifdef BSON_EXTRA_ALIGN ...
改成
#define BSON_ALIGNED_BEGIN(_N) #define BSON_ALIGNED_END(_N)
四、生成微软工程文件
参考:http://mongoc.org/libmongoc/current/installing.html
set path=%path%;C:\cmake-3.15.3-win64-x64\bin
源代码里已经有一个build,按照
不要按照文档的写法:
cmake -G "Visual Studio 14 2015 Win64" \ "-DCMAKE_INSTALL_PREFIX=C:\mongo-c-driver" \ "-DCMAKE_PREFIX_PATH=C:\mongo-c-driver" \ ..
多是Windows不支持反斜杠表示的多行命令,我也不熟悉。
把它们写在一行里,若是是 Visual Studio 2013,这里要写成-G "Visual Studio 12 2013 Win64"。
五、打开Visual Studio编译环境
菜单里打开“Visual Studio 2013”(这是我用的版本,其余版本本身发现,应该都差很少。),选择“VS2013 x64 Native Tools Command Prompt”。
进入目录C:\mongo-c-driver-1.15.1\cmake-build,运行
msbuild.exe /p:Configuration=RelWithDebInfo ALL_BUILD.vcxproj
出现不少不少黄色警告信息,暂时无论,继续安装
msbuild.exe INSTALL.vcxproj
仍然是不少警告,但没有报错,查看C:\mongo-c-driver,库文件已经生成。
六、json-c
网址:https://github.com/json-c/json-c
虽然没有说明怎么编译,强大的cmake仍是让咱们轻松完成。
克隆完毕,按照上边mongodb使用相同方式编译便可。