Linux下Mongodb的C++操作配置

首先安装MongoDB,最简单的安装方法在终端输入:

sudo apt-get install mongodb

如果出错就:sudo apt-get update 更新下

然后启动数据库MongoDB:mongo。默认连接到test。然后就可以在Shell下简单操作Mongodb了。

============================安装pcre,scons(Mongodb辅助工具),boost库==================================

下载pcre http://sourceforge.net/projects/pcre/files/pcre/8.00/

    #tar pcre-8.00.tar.gz
    #cd pcre-8.00
    #./configure   
    #make install                             //pcre完成
然后终端下输入:sudo apt-get install scons   //scons安装完成
安装boost库
下载:wget -O boost_1_54_0.tar.bz2 http://downloads.sourceforge.net/project/boost/boost/1.54.0/boost_1_54_0.tar.bz2?r=http%3A%2F%2Fwww.boost.org%2Fusers%2Fhistory%2Fversion_1_54_0.html&ts=1375162670&use_mirror=jaist //下载boost包,我用的是1.54
解压:tar --bzip2 -xf ./boost_1_54_0.tar.bz2
开始编译,全部编译耗时太多,所以我仅选择我需要的库:
先用下面的命令查看有多少库可以编译:./bootstrap.sh --show-libraries
Building Boost.Build engine with toolset gcc... tools/build/v2/engine/bin.linuxx86_64/b2


The following Boost libraries have portions that require a separate build
and installation step. Any library not listed here can be used by including
the headers only.


The Boost libraries requiring separate building and installation are:
    - atomic
    - chrono
    - context
    - coroutine
    - date_time
    - exception
    - filesystem
    - graph
    - graph_parallel
    - iostreams
    - locale
    - log
    - math
    - mpi
    - program_options
    - python
    - random
    - regex
    - serialization
    - signals
    - system
    - test
    - thread
    - timer
    - wave

然后就编译我要的库:./bootstrap.sh --with-libraries=system,filesystem,log,thread
Building Boost.Build engine with toolset gcc... tools/build/v2/engine/bin.linuxx86_64/b2
Unicode/ICU support for Boost.Regex?... not found.
Generating Boost.Build configuration in project-config.jam...


Bootstrapping is done. To build, run:


    ./b2
    
To adjust configuration, edit 'project-config.jam'.
Further information:


   - Command line help:
     ./b2 --help
     
   - Getting started guide: 
     http://www.boost.org/more/getting_started/unix-variants.html
     
   - Boost.Build documentation:
     http://www.boost.org/boost-build2/doc/html/index.html

然后运行下面的命令完成编译: ./b2
编译需要一段时间,完成后:The Boost C++ Libraries were successfully built!
    The following directory should be added to compiler include paths:
   /usr/src/boost_1_54_0
  The following directory should be added to linker library paths:
  /usr/src/boost_1_54_0/stage/lib

再运行./b2 install 命令,默认安装在

/usr/local/lib目录下

头文件在

/usr/local/include/boost目录下

install 后面可以加参数--prefix=/usr                                                                          //boost库安装完成

===============================MongoDB c++ driver======================

首先获取源代码:git clone https://github.com/mongodb/mongo-cxx-driver.git

然后切换分支:git checkout 26compat

然后用下面的命令编译:scons --prefix=/usr --use-system-boost --sharedclient --full install-mongoclient

   这个命令会编译出.so和.a库,位于build目录:
# ls build/linux2/use-system-boost/libmongoclient.a -alh
  -rw-r--r-- 1 root root 57M  5月 10 23:35 build/linux2/use-system-boost/libmongoclient.a
  # ls build/linux2/use-system-boost/libmongoclient.so -alh
  -rwxr-xr-x 1 root root 20M  5月 10 23:37 build/linux2/use-system-boost/libmongoclient.so


并且安装到了/usr/lib/目录下,头文件在/usr/include目录下:
# ls /usr/lib/libmongoclient.* -alh
-rw-r--r-- 1 root root 57M  5月 10 23:35 /usr/lib/libmongoclient.a
-rwxr-xr-x 1 root root 20M  5月 10 23:37 /usr/lib/libmongoclient.so


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值