MongoDB C++ Driver and "-std=c++1y -O3"

44 views
Skip to first unread message

Neslisah Torosdagli

unread,
Jun 6, 2015, 1:11:02 AM6/6/15
to mongod...@googlegroups.com
I am developing a client-server application using mongoDB on Ubuntu 14.02.2 with C++ Legacy Driver. Clients do not connect to mongoDB but a server running on the device communicates with mongoDB.

I am using compiler flag "-std=c++1y -O3" in order to compile my project. However, if I use "-std=c++1y -O3", mongo::client::initialize() call causes segmentation fault. 

In order to test what is going on, I created a simple main.cpp file to connect to my mongodb, query and insert objects to db, and then I verified that although it works nicely without "-std=c++1y -O3", it causes segmentation fault at initialize() call when "-std=c++1y -O3" is used.

I thought it may be due to reason that mongoDB C++ driver is not built with this flag, and tried to build mongoDB C++ driver by "-std=c++1y -O3", but I could not find out how to do that either.

Please Suggest,
Thanks and Kind Regards,
Neslisah.

Andrew Morrow

unread,
Jun 6, 2015, 7:37:14 AM6/6/15
to mongod...@googlegroups.com

Hi Neslisah -

When using the legacy driver in C++11 (or C++14) mode, you must ensure that all components are compiled with the same language specification flag. Of particular note, this means that the boost library that the driver links against must be compiled with C++11, your application must be compiled in C++11 mode, and the legacy driver must be compiled in C++11 mode. Replace '11' with '14' above as needed.

This can be tricky, especially if you are using the system version of boost. Boost unfortunately does not provide a stable ABI when built with different language standards.

The legacy driver can be built in C++11 mode by passing the --c++11 flag to the SCons invocation you use to build the driver. We don't currently offer built in support for building in C++14 mode. I recommend that you file a ticket at https://jira.mongodb.org/browse/CXX requesting that we add support for building in C++14 mode.

Similarly, you must also ensure that the legacy driver, boost, and your application are compiled against the same C++ runtime library (libstdc++, libc++, etc.). An inconsistency here is a frequent cause of crashes like the one you are experiencing. The --libc++ SCons flag will select libc++ if you need that.

Finally, depending on the level of stability required, you might be interested in trying out the new C++11 driver: https://www.mongodb.com/blog/post/introducing-new-c-driver. It supports C++11 and C++14, has a completely new interface, and does not have a dependency on boost (though it does currently depend on the development version of the MongoDB C driver). We anticipate a stable release of the C++11 driver this summer.

Thanks,
Andrew


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/cb9c72bd-0f2e-45e1-bd20-3cfce2baed02%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages