I have extensively looked into this segmentation fault. I think my instance is not properly initialized on start of the application. I have the folllowing issue (see stackoverflow post: [here])(c++ - Segmentation fault in mongocxx driver - Stack Overflow)
This is my simplified main function which gives me a segmentation fault. Frankly, any command gives me the same segmentation fault. I have ensured that libmongoc 1.17 is installed an mongocxx 3.6.2. In the stackoverflow post I have also provided the CLion backtrace.
int main()
{
mongocxx::instance inst{}; // This should be done only once.
mongocxx::uri uri("mongodb://10.10.10.123:27017");
mongocxx::client client(uri);
mongocxx::database _db = client["test"];
using namespace bsoncxx::builder::basic;
auto doc = make_document(kvp("ismaster", 1));
auto res = _db.run_command(doc.view()); <----- Segmentation Fault
}
How can I ensure that the instance is correctly initialized? Should I call mongoc_init() explicitly or is this handled in the instance call?
Many thanks for your help.
Regards,
Laurens
EDIT: As I’m compiling for C++17 I did not select a polyfill. When I tried installing mongocxx with the polyfill I ran into compilation errors.