[转]MongoDB c++驱动安装与使用
生活随笔
收集整理的這篇文章主要介紹了
[转]MongoDB c++驱动安装与使用
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
- 獲取源碼:git clone https://github.com/mongodb/mongo-cxx-driver.git,解壓
- 安裝編譯工具scons:yum install -y scons
- 編譯:進(jìn)入mongo-cxx-driver目錄,執(zhí)行:scons --prefix=/home/work/mongo/ --sharedclient install
- 驅(qū)動(dòng)已被安裝在/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
- 上面的編譯選項(xiàng)中,mongo、lib與tutorial.cpp位于同一目錄,mongo即是第一步中指定的安裝目錄,lib存放其他依賴庫(kù),如boost。
更多文章,請(qǐng)關(guān)注零一積流
轉(zhuǎn)載于:https://www.cnblogs.com/rd-log/p/4810327.html
總結(jié)
以上是生活随笔為你收集整理的[转]MongoDB c++驱动安装与使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 程序员所应具备的品质
- 下一篇: MVC模板页