[转]MongoDB c++驱动安装与使用
生活随笔
收集整理的這篇文章主要介紹了
[转]MongoDB c++驱动安装与使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
- 獲取源碼:git clone https://github.com/mongodb/mongo-cxx-driver.git,解壓
- 安裝編譯工具scons:yum install -y scons
- 編譯:進入mongo-cxx-driver目錄,執行:scons --prefix=/home/work/mongo/ --sharedclient install
- 驅動已被安裝在/home/work/mongo中
- 編譯示例程序
#include <cstdlib> #include <iostream> #include "mongo/client/dbclient.h" // for the driver void run() { mongo::DBClientConnection c; c.connect("localhost"); } int main() { mongo::client::initialize(); try { run(); std::cout << "connected ok" << std::endl; } catch( const mongo::DBException &e ) { std::cout << "caught " << e.what() << std::endl; } return EXIT_SUCCESS; } - gcc tutorial.cpp -I./mongo/include -L./lib/ -L./mongo/lib -lmongoclient -Wl,-rpath=./lib/ -o tutorial
- 上面的編譯選項中,mongo、lib與tutorial.cpp位于同一目錄,mongo即是第一步中指定的安裝目錄,lib存放其他依賴庫,如boost。
更多文章,請關注零一積流
轉載于:https://www.cnblogs.com/rd-log/p/4810327.html
總結
以上是生活随笔為你收集整理的[转]MongoDB c++驱动安装与使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 程序员所应具备的品质
- 下一篇: 数据结构应用实例#栈#迷宫寻路