install mongodb C++ driver

linux安裝mongo c++ driver,出現Checking for C++ library boost_thread-mt... no的解決辦法html

  • build mongo-cxx-driver-v2.2

從mongodb官方網站下載mongo c++ driver程序包:mongodb-linux-x86_64-2.2.0.tar。解壓後運行scons。linux

$ cd mongo-cxx-driver-v2.2c++

$ sconsmongodb

scons: Reading SConscript files ...bootstrap

Checking for C++ library boost_thread-mt... noubuntu

Checking for C++ library boost_thread... no網站

出現問題。可見它依賴於boost庫。ui

  • 用apt-get安裝boost開發和文檔庫

$ sudo apt-get install libboost-dev libboost-dochtm

安裝成功後,回到mongo-cxx-driver-v2.2目錄再次運行scons,現象依舊。blog

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

相關文章
相關標籤/搜索