Mongo C ++驱动程序:mongo / client / dbclient.h:没有这样的文件或目录

时间:2013-07-20 01:16:17

标签: c++ mongodb

我正在尝试在我的机器上安装MongoDB C ++驱动程序。我按照here的指示,似乎一切都安装成功。不过,我似乎无法包含标题。这是一个简单的测试程序:

#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++ app/tutorial.cpp -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system -o tutorial
app/tutorial.cpp:3:35: error: mongo/client/dbclient.h: No such file or directory
app/tutorial.cpp: In function ‘void run()’:
app/tutorial.cpp:6: error: ‘mongo’ has not been declared
app/tutorial.cpp:6: error: expected `;' before ‘c’
app/tutorial.cpp:7: error: ‘c’ was not declared in this scope
app/tutorial.cpp: In function ‘int main()’:
app/tutorial.cpp:14: error: ISO C++ forbids declaration of ‘mongo’ with no type
app/tutorial.cpp:14: error: expected `)' before ‘::’ token
app/tutorial.cpp:14: error: expected `{' before ‘::’ token
app/tutorial.cpp:14: error: ‘::DBException’ has not been declared
app/tutorial.cpp:14: error: ‘e’ was not declared in this scope
app/tutorial.cpp:14: error: expected `;' before ‘)’ token

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:4)

app/tutorial.cpp:3:35: error: mongo/client/dbclient.h: No such file or directory表示g ++难以找到已安装的标头。在您链接到的教程中,建议的编译命令下面的框表示

  

您可能需要使用-I和-L来指定mongo和boost标头和库的位置。

我将假设安装程序将您的头文件放在/usr/local/includelibmongoclient.a中的库(例如/usr/local/lib)中。然后,尝试调整编译命令以读取

g++ -I/usr/local/include -L/usr/local/lib -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system app/tutorial.cpp -o tutorial