Why is there an access violation on connecting to MongoDB from C++?

允我心安 提交于 2019-12-13 09:00:48

问题


When I try to run this little piece of code

#include <iostream>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>

int main(int argc, char **argv)
{
    mongocxx::client client{mongocxx::uri{}};
    mongocxx::database db = client["xyz"];
    std::cout << "Connected to xyz." << std::endl;
}

I always get this warning

Exception thrown at 0x00007FFF7815F1FD (libmongoc-1.0.dll) in Test.exe: 0xC0000005: Access violation writing location 0x0000000000000020.

Can someone help?


回答1:


I fixed it by adding

mongocxx::instance instance{};

as the first line of code in the main function.



来源:https://stackoverflow.com/questions/42191206/why-is-there-an-access-violation-on-connecting-to-mongodb-from-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!