Compiling MongoDB C++ Driver, Boost Error (Windows)

I am trying to compile the MongoDB C++ Driver on Windows. I am using the SCons "Make" Tool. and it is giving me a Boost Error, I have boot libraries but I am unsure how to get it to link with the SCons Build file. I am use to just adding the reference in VS. It looks like i need an environment variable reference but I am not sure.

here is the Error:

scons mongoclient
scons: Reading SConscript files ...
Checking for C++ library boost_thread-mt... (cached) no
Checking for C++ library boost_thread... (cached) no
Checking for C++ library boost_filesystem-mt... (cached) no
Checking for C++ library boost_filesystem... (cached) no
Checking for C++ library boost_system-mt... (cached) no
Checking for C++ library boost_system... (cached) no
scons: done reading SConscript files.
scons: Building targets ...
cl /Fobuild\mongo\bson\oid.obj /c src\mongo\bson\oid.cpp /TP /nologo /EHsc /O2 /
D_SCONS /DMONGO_EXPOSE_MACROS /Ibuild /Isrc /Ibuild\mongo /Isrc\mongo
oid.cpp
src\mongo/pch.h(48) : fatal error C1083: Cannot open include file: 'boost/shared
_ptr.hpp': No such file or directory
scons: *** [build\mongo\bson\oid.obj] Error 2
scons: building terminated because of errors.

in the SConstruct file I find the following but not sure what exactly means for finding the boost libraries.

boostLibs = ["thread", "filesystem", "system"]
conf = Configure(env)
for lib in boostLibs:
    if not conf.CheckLib(["boost_%s-mt" % lib, "boost_%s" % lib],
                         language="C++"):
        if not win:
            Exit(1)
conf.Finish()
share improve this question
 
 
Since you're having trouble with the C++ install, can I assume you had no problems with the C driver build? Because that's where I'm stuck right now. On mongodb-dot-org C++ MongoDB Driver page it says download the C++ driver, then go to this link to install it: github.com/mongodb/mongo-cxx-driver/wiki/… The first thing that page tells you to do is install the C driver (which also builds libbson, if needed). Then it instructs to compile the C++ driver. Am I reading it wrong? Is it a single page for both installs, & I'm only supposed to do the latter? –  Luv2code  Jul 22 '15 at 17:30

2 Answers

up vote 2 down vote accepted

So I was finally able to the boost Libs to show up by finding this:

scons --extrapath=c:\boost

the C:\boost being the directory for boost. I am now experiencing compiler errors but that is further than before.

share improve this answer
 

You can add additional include path using the --cpppath option

--cpppath : Include path if you have headers in a nonstandard directory

Moreover remember to compile your boot library and to link to the correct folder containing the boost library .lib files

--libpath : Library path if you have libraries in a nonstandard directory

Thus you should issue a command similar to:

scons --cpppath=c:\boost --libpath=c:\boost\stage\lib
share improve this answe

MongoDB C++ Driver编译

  676人阅读  评论(0)  收藏  举报

安装方法:最新版的,官网还在测试期,不过一个很大的提升就是Driver和Server代码分开了。

1、下载
https://codeload.github.com/mongodb/mongo-cxx-driver/zip/legacy-1.0.0-rc0


2、安装
d:\mongo-cxx-driver-legacy-1.0.0-rc0>c:Python27\Scripts\scons.py install-mongoclient --cpppath=d:\boost_1_55_0 --libpath=d:\boost_1_55_0\stage\lib --32 --dbg=on


3、将install目录的include和lib拷贝到你的项目下
VS环境配置:


目录:  头文件  ..\Src\mongodb\include;
库目录  ..\Src\mongodb\lib;
lib:libmongoclient-sgd.lib;ws2_32.lib;
预处理定义:BOOST_ALL_NO_LIB;
STATIC_LIBMONGOCLIENT(也可以再程序中定义)
#include <WinSock2.h>

下面是一些其他版本。

一、关于官网稳定版本 -- mongodb-src-r2.4.12

相关工具:boost_1_49_0或者boost_1_55_0;Scons依赖Python生成,故都需要;

现在我们编译指令:

命令行:切换到源码安装目录,执行C:\Python27\Scripts\scons.py --cpppath=d:\boost_1_55_0 --libpath=d:\boost_1_55_0\stage\lib --dd --32 mongoclient

(Tip:--dd Debug带调试信息 --32 支持32位程序 生成目标是mongoclient.lib  当然有相关其他参数:可以查看官网,也可以直接看源码目录下的SConstruct中add_option函数)

生成之后,用vs打开创建一个工程:

1、包含boost相关.cpp,可以直接将D:\mongodb-src-r2.4.12\src\mongo\client\examples\simple_client_demo.vcxproj中boost筛选器中内容拷贝到你建立的项目中

原因是我当前用的是boost_1_55_0而非自带中的1_44_0,

2、项目环境配置:(将src下的东西拷到自己的项目下吧,并且将那个lib拿出来)

     [1]、头文件目录:..\Src\mongodb\src;..\src\mongodb\src\third_party\boost;

     [2]、库目录:自己放哪配哪

     [3]、加上预处理器定义:BOOST_ALL_NO_LIB,

     [4]、添加三个必备lib, Dbghelp.lib;ws2_32.lib;mongoclient.lib;

(注意我的是--dd,所以运行库配置必须是MTd,如果是release版本请重新生成--release ,多少位程序自己顶--32/--64,生成的lib将会比debug的lib大很多253M左右,相对应的运行库配置成MT)

3、如果程序出现无法解析的xxx,那基本都是缺少lib,上面包含lib全包含就行了。最后有个tss_cleanup_implemented无法解析,直接在程序段加个这个代码吧!或者你自己找到那个lib或.cpp到项目编译也行。(考虑到这个函数在boost里基本都是空实现,应该没什么大碍,故此修改的!)

namespace boost
{
void tss_cleanup_implemented(void){}
}

 

二、新版本编译

这个版本比较新的版本,支持的编译选项较官网提供稳定版本多,支持--dynamic-windows选项(就是vs种MD/MDd模式,支持DLL的),

因为我们项目需要接口使用复杂类型(Tip:如std::string等,会存在内存申请和释放不在一个模块问题!,MT模式就会直接崩溃,而MD模式会在同一个地方申请和释放,不会存在问题)

首先去看下安装过程:https://github.com/mongodb/mongo-cxx-driver/wiki/Download%20and%20Compile

编译选项:

D:\mongo-cxx-driver-legacy-1.0.0-rc0>c:\Python27\Scripts\scons.py install-mongoc
lient --cpppath=d:\boost_1_55_0 --libpath=d:\boost_1_55_0\stage\lib --dynamic-wi
ndows --32 --dbg=on


[cpp]  view plain  copy
  1. #if 1     
  2. ///< 源码版本:mongo-cxx-driver-legacy-1.0.0-rc0,使用说明  
  3. #pragma warning(disable:4996)  
  4. // Consumers of the MongoDB C++ client library must define STATIC_LIBMONGOCLIENT when including  
  5. // this header if they intend to link against the static version of the library. This is best  
  6. // handled by adding STATIC_LIBMONGOCLIENT to the list of definitions passed on each compile  
  7. // invocation.  
  8. ///< 注意1:By Lenny(调用静态MongoDBClient需定义此宏进行编译,可参见#include <mongo\bson\bson.h>)  
  9. #define STATIC_LIBMONGOCLIENT   
  10.   
  11. ///< 注意2:需要此宏_WINSOCK2API_  
  12. #include <WinSock2.h> //  _WINSOCK2API_  
  13.   
  14. ///< 注意3:不同模式对库的选择  
  15. /** 
  16.  *  MT/MTd/MD/MDd   d-->DLL, D-->Debug 
  17.  *  s-->static,不是dll,及MT/MTd模式 
  18.  *  gd-->dbg=on 即Debug,及MT/MD模式 
  19.  */  
  20. #ifdef _DLL   
  21.     #ifdef _DEBUG //MDd  
  22.         #pragma comment(lib, "libmongoclient-gd.lib")  
  23.     #else   //MD  
  24.         #pragma comment(lib, "libmongoclient.lib")  //  
  25.     #endif  
  26. #else   
  27.     #ifdef _DEBUG   //MTd  
  28.         #pragma comment(lib, "libmongoclient-sgd.lib")  
  29.     #else   //MT  
  30.         #pragma comment(lib, "libmongoclient-s.lib")  
  31.     #endif  
  32. #endif  
  33. #endif  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值