红联Linux门户
Linux帮助

编译使用C++ MongoDB Driver

发布时间:2016-07-04 15:20:39来源:linux网站作者:陈帅陪马大大为软件献
在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
$ ./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 ..
make ; sudo make install
 
添加环境变量
vim ~/.bashrc
export LD_LIBRARY_PATH=/usr/lib/:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:$PKG_CONFIG_PATH //添加这个环境变量,不然pkg-config找不到库的路径
 
本文永久更新地址:http://www.linuxdiyf.com/linux/22063.html