MongoDB C Driver Building on CentOS

Building on Unix

Prerequisites

OpenSSL is required for authentication or for SSL connections to MongoDB. Kerberos or LDAP support requires Cyrus SASL.

To install all optional dependencies on RedHat / Fedora:

$ sudo yum install pkg-config openssl-devel cyrus-sasl-devel
On Debian / Ubuntu: $ sudo apt-get install pkg-config libssl-dev libsasl2-dev
On FreeBSD: $ su -c 'pkg install pkgconf openssl cyrus-sasl'

Building from a release tarball

Unless you intend on contributing to the mongo-c-driver, you will want to build from a release tarball.

The most recent release of libmongoc is 1.8.1 and can be downloaded here. The following snippet will download and extract the driver, and configure it:

$ wget https://github.com/mongodb/mongo-c-driver/releases/download/1.8.1/mongo-c-driver-1.8.1.tar.gz
$ tar xzf mongo-c-driver-1.8.1.tar.gz
$ cd mongo-c-driver-1.8.1
$ ./configure --disable-automatic-init-and-cleanup 

亲测:

 https://github.com/mongodb/mongo-c-driver/releases/download/1.8.1/mongo-c-driver-1.8.1.tar.gz 这个地址下载超慢 

所以还是从 git 下载源码

Building from git

To build an unreleased version of the driver from git requires additional dependencies.

RedHat / Fedora:

$ sudo yum install git gcc automake autoconf libtool
Debian / Ubuntu: $ sudo apt-get install git gcc automake autoconf libtool
FreeBSD: $ su -c 'pkg install git gcc automake autoconf libtool'

Once you have the dependencies installed, clone the repository and build the current master or a particular release tag:

$ git clone https://github.com/mongodb/mongo-c-driver.git
$ cd mongo-c-driver
$ git checkout x.y.z # To build a particular release
$ ./autogen.sh --with-libbson=bundled
$ make
$ sudo make install

1.

  下载 mongo-c-driver-r1.6 源码:

    https://github.com/mongodb/mongo-c-driver(GitHub驱动源码,这个 src/libbson 文件夹里面是空的,要单独下载)

  下载 libbson-r1.6 源码:

     https://github.com/mongodb/mongo-c-driver/tree/r1.6/src

2.

  解压:

    unzip mongo-c-driver-r1.6.zip

    unzip libbson-r1.6.zip

3.

  将 libbson 源码 拷贝 至 mongo-c-driver-r1.6/src/libbson 目录

4. 

  sudo yum install pkg-config openssl-devel cyrus-sasl-devel

  ./autogen.sh --with-libbson=bundled (得先安装 libtoll ,否则会报错。sudo yum install libtool*)

  make

  sudo make install

安装完成的库和头文件目录:

  /usr/local/lib

  /usr/local/include

  MongoDB C Driver Building on CentOS

  MongoDB C Driver Building on CentOS

API 用法详见:http://www.cnblogs.com/SZxiaochun/p/5848455.html

注意:

  使用库的时候报错:

    error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

原因:

  程序按照默认共享库路径找不到该共享库文件。

解决方法:

  详见:http://www.cnblogs.com/SZxiaochun/p/7685499.html

上一篇:华为章宇:如何学习开源项目及Ceph的浅析


下一篇:URAL 1297 Palindrome 最长回文子串