本文的安装过程以archlinux为例
首先安装boost
sudo pacman -S boost
下载C++ diver
http://dl.mongodb.org/dl/cxx-driver
解压之后,将src中的mongo拷入 /usr/src下
用官网的例子,创建一个test.cpp
#include <cstdlib>
#include <iostream>
#include "mongo/client/dbclient.h"
void run() {
mongo::DBClientConnection c;
c.connect("localhost");
}
int main() {
try {
run();
std::cout << "connected ok" << std::endl;
} catch( const mongo::DBException &e ) {
std::cout << "caught " << e.what() << std::endl;
}
return EXIT_SUCCESS;
}
编译一下
g++ test.cpp -pthread -lmongoclient -lboost_system -o test
运行
./test
输出 connected ok 成功