MongoC++驱动程序:Mongo/client/dbclient.h:没有这样的文件或目录
Mongo C++ Driver: mongo/client/dbclient.h: No such file or directory
我正在尝试在我的机器上安装MongoDB C++驱动程序。我按照这里的指示进行了操作,一切似乎都安装成功了。尽管如此,我似乎无法将标题包括在内。这里有一个简单的测试程序:
#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
如有任何帮助,我们将不胜感激。
行app/tutorial.cpp:3:35: error: mongo/client/dbclient.h: No such file or directory
表示g++很难找到已安装的标头。在您链接到的教程中,建议编译命令下方的框中显示
您可能需要使用-I和-L来指定mongo和boost头文件和库的位置。
我假设安装过程将头文件放在/usr/local/include
中,将库(例如libmongoclient.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
相关文章:
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 文本文件中的单词链表
- CMake-按正确顺序将项目与C运行时对象文件链接
- 使用新行和不使用新行读取文件
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 挂起和取消挂起一个文件DLL
- 如何确定我已使用非编码文件到达 EOF?
- 命名空间中具有.h和.cpp文件的类
- 如何使用ndk-build.cmd构建Android.so文件
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- 读取文件并输入到矢量中
- 在C++中查找文件
- c++库的公共头文件中应该包含什么
- 用c++从输入文件中读取另一行
- Cppcheck生成xml转储文件
- 读取文件的最后一行并输入到链接列表时出错
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- MongoC++驱动程序:Mongo/client/dbclient.h:没有这样的文件或目录
- 在mongo中存储大文件(但不是媒体)的正确方法