[英]Why is the mongo C++ driver giving me compilation errors?
I have installed mongo straight from github using 我已经使用github直接安装了mongo
sudo scons --full install
and have the following example source file 并具有以下示例源文件
#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;
}
When I run 当我跑步
g++ tutorial.cpp -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem
-lboost_program_options -lboost_system -o tutorial
I am given the error 我得到了错误
In file included from /usr/local/include/mongo/util/net/hostandport.h:21:0,
from /usr/local/include/mongo/util/net/message.h:24,
from /usr/local/include/mongo/client/dbclientinterface.h:30,
from /usr/local/include/mongo/client/connpool.h:23,
from /usr/local/include/mongo/client/dbclient.h:32,
from tutorial.cpp:3:
/usr/local/include/mongo/db/server_options.h:34:51: fatal error:
mongo/util/options_parser/environment.h: No such file or directory
compilation terminated.
I looked into /usr/local/include/mongo/util, but the options_parser folder is not in there. 我查看了/ usr / local / include / mongo / util,但是options_parser文件夹不在其中。
I had the same error myself, after following the write-up on MongoDB's website. 在遵循MongoDB网站上的文章之后,我自己也遇到了同样的错误。 What I ended up doing was copying the headers from the download directory to my include directory.
我最终要做的是将标题从下载目录复制到我的包含目录。 Ie
即
sudo cp -R ~/Downloads/mongo-master/src/mongo/util/options_parser /usr/local/include/mongo/util/
Where mongo-master is the name of the extracted directory from MongoDB's GitHub. 其中mongo-master是从MongoDB的GitHub提取的目录的名称。 Hopefully this helps you.
希望这对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.