Chinaunix首页 | 论坛 | 博客
  • 博客访问: 291826
  • 博文数量: 82
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 874
  • 用 户 组: 普通用户
  • 注册时间: 2015-03-21 09:58
个人简介

traveling in cumputer science!!

文章分类

全部博文(82)

文章存档

2016年(13)

2015年(69)

我的朋友

分类: NOSQL

2015-12-29 22:21:39

1。安装C++版驱动之前,先安装C版的驱动,过程如下:

我的安装平台:ubuntu14.04     64位,其他平台可参考:http://api.mongodb.org/c/current/installing.html#installing-unix
       (1) 安装PDK:

点击(此处)折叠或打开

  1. sudo apt-get install pkg-config libssl-dev libsasl2-dev
        (2)下载安装包,并配置:

点击(此处)折叠或打开

  1. $ wget https://github.com/mongodb/mongo-c-driver/releases/download/1.3.0/mongo-c-driver-1.3.0.tar.gz
  2. $ tar xzf mongo-c-driver-1.3.0.tar.gz
  3. $ cd mongo-c-driver-1.3.0
  4. $ ./configure
                安装成功并显示如下内容:

点击(此处)折叠或打开

  1. libmongoc was configured with the following options:

  2. Build configuration:
  3. Enable debugging (slow) : no
  4. Compile with debug symbols (slow) : no
  5. Enable GCC build optimization : yes
  6. Enable automatic binary hardening : yes
  7. Code coverage support : no
  8. Cross Compiling : no
  9. Fast counters : no
  10. SASL : sasl2
  11. SSL : yes
  12. Libbson : bundled

  13. Documentation:
  14. Generate man pages : no
  15. Install man pages : no
               (3)make并安装,需要几分钟的过程:

点击(此处)折叠或打开

  1. $ make
  2. $ sudo make install


2。C++版的安装过程:

安装前需求: 系统:Linux 或 OSX 编译器:clang++ 3.4+ 或 g++ 4.9+  Cmake:CMake 3.1+
        (1)安装新版的Cmake:
                卸载旧版本:

点击(此处)折叠或打开

  1. sudo apt-get remove cmake
                新版本下载:
                解压安装:

点击(此处)折叠或打开

  1. tar -zxvf cmake-3.4.1.tar.gz
  2. cd cmake-3
  3. ./bootstrap && make && make install
            (2)下载安装C++驱动:

点击(此处)折叠或打开

  1. git clone -b master https://github.com/mongodb/mongo-cxx-driver
  2. cd mongo-cxx-driver/build
  3. cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local PKG_CONFIG_PATH=CDRIVER_INSTALL_PATH/lib/pkgconfig ..
  4. sudo make && sudo make install


3。解决问题

在测试C驱动的时候,编译链接生成可执行文件,例子是/mongo-c-driver-1.3.0/examples下面的example-client.c
执行如下命令:

点击(此处)折叠或打开

  1. gcc example-client.c -o example $(pkg-config --cflags --libs libmongoc-1.0)
生成后,运行时会有问题:

点击(此处)折叠或打开

  1. ./example
  2. ./example: error while loading shared libraries: libmongoc-1.0.so.0: cannot open shared object file: No such file or directory
查看链接问题:

点击(此处)折叠或打开

  1. ldd example
  2.         linux-vdso.so.1 => (0x00007fffd09ca000)
  3.     libmongoc-1.0.so.0 => not found
  4.     libbson-1.0.so.0 => not found
  5.     libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9c1a0c5000)
  6.     /lib64/ld-linux-x86-64.so.2 (0x00007f9c1a48a000)
可知相应的库文件没有找到。
测试解决办法,成功运行:

点击(此处)折叠或打开

  1. LD_LIBRARY_PATH=/usr/local/lib ./example
查看:

点击(此处)折叠或打开

  1. cat ld.so.conf
  2. include /etc/ld.so.conf.d/*.conf
  3. cd /etc/ld.so.conf.d/
  4. fakeroot-x86_64-linux-gnu.conf  x86_64-linux-gnu_EGL.conf
    i686-linux-gnu.conf             x86_64-linux-gnu_GL.conf
    libc.conf                       zz_i386-biarch-compat.conf
    x86_64-linux-gnu.conf
可知链接库没有mongoc.conf配置文件,因此创建,并在文件中加入mongoc库的路径:

点击(此处)折叠或打开

  1. cd /usr/local/lib/
  2. ls
  3. libbson-1.0.la libmongoc-1.0.la libmongocxx.a
  4. libbson-1.0.so libmongoc-1.0.so libmongocxx.so
  5. libbson-1.0.so.0 libmongoc-1.0.so.0 libmongocxx.so.0
  6. libbson-1.0.so.0.0.0 libmongoc-1.0.so.0.0.0 libmongocxx.so.0.3.0
  7. libbsoncxx.a libmongoc-priv.la pkgconfig
  8. libbsoncxx.so libmongoc-priv.so python2.7
  9. libbsoncxx.so.0 libmongoc-priv.so.0 python3.4
  10. libbsoncxx.so.0.3.0 libmongoc-priv.so.0.0.0 site_ruby

  11. cd /etc/ld.so.conf.d/
  12. sudo vi mongoc.conf
然后在上面新建的mongoc.conf文件中加入,相应的库路径:/usr/local/lib/即可解决问题



参考链接:
pkg-config 用法:http://www.cppblog.com/colorful/archive/2012/05/05/173750.html
mongoC++安装指导:(New-Driver)
mongoC安装指导:http://api.mongodb.org/c/current/?_ga=1.224779610.177216698.1449303645
C 驱动使用实例:http://api.mongodb.org/c/current/tutorial.html#starting-mongod






阅读(6278) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~