- build mongo-cxx-driver-v2.2
从mongodb官方网站下载mongo c++ driver程序包:mongodb-linux-x86_64-2.2.0.tar。解压后运行scons。
$ cd mongo-cxx-driver-v2.2
$ scons
scons: Reading SConscript files ...
Checking for C++ library boost_thread-mt... no
Checking for C++ library boost_thread... no
出现问题。可见它依赖于boost库。
- 用apt-get安装boost开发和文档库
$ sudo apt-get install libboost-dev libboost-doc
安装成功后,回到mongo-cxx-driver-v2.2目录再次运行scons,现象依旧。
- 用apt-get安装全部boost库
$ sudo apt-get install libboost*
…
The following packages have unmet dependencies:
libboost-date-time1.42-dev : Conflicts: libboost-date-time1.40-dev but 1.40.0-6ubuntu1 is to be installed
libboost-filesystem1.42-dev : Conflicts: libboost-filesystem1.40-dev but 1.40.0-6ubuntu1 is to be installed
…
libboost1.42-dbg : Conflicts: libboost1.40-dbg but 1.40.0-6ubuntu1 is to be installed
libboost1.42-dev : Conflicts: bcp
Conflicts: libboost1.40-dev but 1.40.0-6ubuntu1 is to be installed
libboost1.42-doc : Conflicts: libboost1.40-doc but 1.40.0-6ubuntu1 is to be installed
E: Broken packages
Boost内部依赖出问题,干脆下载源文件自己build。
- 下载boost 1.51版本并build
$ cd boost_1_51_0
$ ./bootstrap.sh
…
$ ./b2
…
$ sudo ./b2 install
…
这个过程很长,需要耐心等待。
- 再次build mongo-cxx-driver-v2.2
build成功后,回到mongo-cxx-driver-v2.2目录再次运行scons,现象依旧。
$ cd mongo-cxx-driver-v2.2
$ scons
…
In file included from /usr/local/include/boost/filesystem/path.hpp:24,
from src/mongo/util/paths.h:26,
from src/mongo/db/client.h:38,
from src/mongo/db/curop.h:23,
from src/mongo/db/curop-inl.h:1,
from src/mongo/db/instance.h:23,
from src/mongo/db/dbmessage.h:25,
from src/mongo/client/dbclient_rs.cpp:27:
/usr/local/include/boost/filesystem/config.hpp:16: error: #error Compiling Filesystem version 3 file with BOOST_FILESYSTEM_VERSION defined != 3
scons: *** [build/mongo/client/dbclient_rs.o] Error 1
scons: building terminated because of errors.
看来是文件系统版本不兼容。查阅了资料,mongo c++ driver只支持boost filesystem V2。
Boost官网http://www.boost.org/doc/libs/1_51_0/libs/filesystem/doc/index.htm有这么一段话:
This is Version 3 of the Filesystem library. Version 2 is not longer supported. 1.49.0 was the last release of Boost to supply Version 2。
于是决定安装boost 1.49的版本
- 下载boost 1.49版本并build
成功
- 再次build mongo-cxx-driver-v2.2
$ cd mongo-cxx-driver-v2.2
$ scons
$ sudo scons install
大功告成。现在你可以开始用c++编写操作mongoDB的程序了。