- 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的程序了。