0

我需要帮助!如何在 linux 中编译 c++ mongo 项目?

我正在这样做:1)安装boost 2)编译mongodb驱动程序3)尝试编译示例(失败)

我编译的 mongodb 驱动程序存在于 /home/developer/documents/drivers/mongo-cxx-driver-v2.4/build

我正在尝试编译这个文件

#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++ tutorial.cpp -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system -o tutorial

此命令失败。错误消息 - 未找到“mongo/client/dbclient.h”。如何编译这个例子?请帮帮我!

4

1 回答 1

2

您需要使用 -I 和 -L 指定安装 mongo 标头和库的位置:

g++ tutorial.cpp -I/path/to/mongo/include/ -pthread -L/path/to/libmongoclient 
                 -lboost_thread-mt -lboost_filesystem -lboost_program_options 
                 -lboost_system -o tutorial
于 2014-02-10T19:32:59.873 回答