MongoDB C++ 开发环境搭建

来源:互联网 发布:怎么修改淘宝收获地址 编辑:程序博客网 时间:2024/05/20 07:52

编译使用C++ MongoDB Driver

本博客在linux下编译使用C++ MongoDB Driver


准备工作

  • GCC 4.8.2+
  • CMake 3.2+
  • The MongoDB C driver version 1.3.5+
  • boost 1.56+

编译安装MongoDB C Driver

The C++ driver uses libbson and the MongoDB C driver internally.
安装c++driver前需要先安装libbson 和 c driver:

$ sudo apt-get install pkg-config libssl-dev libsasl2-dev

wget https://github.com/mongodb/mongo-c-driver/releases/download/1.3.5/mongo-c-driver-1.3.5.tar.gz

$ tar xzf mongo-c-driver-1.3.5.tar.gz

$cd mongo-c-driver-1.3.5/

$ ./configure

如果都配置正确的话机会看到:

libmongoc was configured with the following options:
Build configuration:
Enable debugging (slow) : no
Compile with debug symbols (slow) : no
Enable GCC build optimization : yes
Enable automatic binary hardening : yes
Code coverage support : no
Cross Compiling : no
Fast counters : no
SASL : sasl2
SSL : yes
Libbson : bundled
Documentation:
Generate man pages : no
Install man pages : no

mongo-c-driver 已经包含了 libbson , make 安装:

$ make

$ sudo make install

编译安装 MongoDB C++ driver

$git clone -b master https://github.com/mongodb/mongo-cxx-driver

$git checkout r3.0.0

$cd build/

$cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..

$sudo make ; //注意这里要加上sudo权限 因为上一条命令加上了 /usr/local

$sudo make install

添加环境变量

vim ~/.bashrc

export LD_LIBRARY_PATH=/usr/lib/:$LD_LIBRARY_PATH

export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:$PKG_CONFIG_PATH //添加这个环境变量,不然pkg-config找不到库的路径

编写实例代码,参考后续博客

参考:

https://github.com/mongodb/mongo-cxx-driver/wiki/Quickstart-Guide-(New-Driver)

1 0
原创粉丝点击