[CXX-565]  mongo::client::initialize() crashes Created: 19/Mar/15  Updated: 23/Mar/15  Resolved: 23/Mar/15

Status: Closed
Project: C++ Driver
Component/s: API
Affects Version/s: legacy-1.0.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Judy Han [X] Assignee: Adam Midvidy
Resolution: Done Votes: 0
Labels: legacy-cxx
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

mongo::client::initialize() crashes when compiler __cplusplus is 201103.
temporary workaround is change
src/mongo/src/stdx/functional.h
to always use boost::function



 Comments   
Comment by Judy Han [X] [ 23/Mar/15 ]

Hi Adam,
Thank for the info! I will keep that in mind.
Thanks!
Judy

Comment by Adam Midvidy [ 23/Mar/15 ]

Hi Judy,

Glad to hear that worked. Also, if you are already using C+11 you should take a look at our new C+11 driver, which can be found here: https://github.com/mongodb/mongo-cxx-driver/tree/master

It is not completely stable yet, but it offers a much more idiomatic API. You can read more about it here: http://www.mongodb.com/blog/post/introducing-new-c-driver

Adam

Comment by Judy Han [X] [ 23/Mar/15 ]

Hi Adam
That works! Thanks!
Judy

Comment by Adam Midvidy [ 23/Mar/15 ]

Can you try passing the -cc and -cxx options to manually specify the location of gcc 4.8 and g++ 4.8 to SCons?

Comment by Judy Han [X] [ 23/Mar/15 ]

Hi Adam,

I did some experiments, following code compiles and runs successfully with or without -std=c++11 flag

#include <vector>
#if !defined(_GLIBCXX_BEGIN_NAMESPACE_VERSION)
#error libstdcxx older than 4.6.0
#endif
int main() { return 0; }

It's almost like something is missing in SConstruct to get the right environment. The reason I say that is it looks like that's how SConstruct decide if we are using libstdc++4.6.0 or older version.

Thanks,
Judy

Comment by Adam Midvidy [ 23/Mar/15 ]

Hi Judy,

Unfortunately this does not seem to be a driver issue, but rather a toolchain misconfiguration. We are only able to assist with issues involving the driver itself. I would suggest contacting Red Hat and asking for assistance on properly enabling devtoolset-2.

Adam

Comment by Judy Han [X] [ 23/Mar/15 ]

Hi Adam,

I did have following for all my tests we discussed:

scl enable devtoolset-2 bash

Thanks!
Judy

Comment by Adam Midvidy [ 23/Mar/15 ]

Hi Judy,

MongoDB C++ driver supports -std=c++11 on RHEL 6.6.

It looks like you have the devtoolset-2 installed, but you need to enable it.

Try

scl enable devtoolset-2 bash

Then recompile the driver with -std=c++11.

Adam

Comment by Judy Han [X] [ 23/Mar/15 ]

Hi Adam,

Just want to clarify that for Redhat 6.6, mongodb c++ driver does not support -std=c++11?

What driver do you recommand if performance is our major concern?

Thanks!
Judy

Comment by Judy Han [X] [ 20/Mar/15 ]

Hi Adam,

I see. Thanks for the information.
We are using Redhat 6.6, it looks like that latest libstdc++.so for Redhat 6.6 is version 4.4.7.
And we are using -std=c++11 for our projects.

Do you have any suggestions?
Thanks!
Judy

Comment by Adam Midvidy [ 20/Mar/15 ]

Judy,

libstdc++4.6.0 is a requirement for compiling the driver with C++11 enabled. If you require compiling the driver in C++11 mode, you should upgrade to a newer libstdc++.

Adam

Comment by Judy Han [X] [ 20/Mar/15 ]

ah, thanks!
here is the output:

scons --cpppath=/home/jhan/Software/boost/boost_1_55_0 --extrapath=/home/jhan/workspace/MTX/publish_linux/opt/mtx --c++11=on --config=force --sharedclient install-examples
scons: Reading SConscript files ...
scons version: 2.0.1
python version: 2 6 6 'final' 0
Checking whether the C++ compiler worksyes
Checking whether the C compiler worksyes
Checking if C++ compiler "g++" is GCC... yes
Checking if C compiler "gcc" is GCC... yes
Checking if C compiler supports -Wno-unused-local-typedefs... no
Checking if C compiler supports -Wno-unused-function... yes
Checking if C compiler supports -Wno-unused-private-field... no
Checking if C compiler supports -Wno-deprecated-declarations... yes
Checking if C compiler supports -Wno-tautological-constant-out-of-range-compare... no
Checking if C compiler supports -Wno-unused-const-variable... no
Checking if C compiler supports -Wno-missing-braces... yes
Checking if we are using libstdc++... yes
Checking for libstdc++ 4.6.0 or better... no
Detected libstdc++ is too old to support C++11 mode

I see, I have:
%rpm -q libstdc++
libstdc++-4.4.7-11.el6.x86_64
libstdc++-4.4.7-11.el6.i686

Is the requirement for libstdc++4.6.0 or better a mongo client driver requirement?
In my devtoolset-2 directory I have:
%cat root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/32/libstdc++.so
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf32-i386)
INPUT ( /usr/lib/libstdc+.so.6 -lstdc+_nonshared )

Thanks!
Judy

Comment by Adam Midvidy [ 19/Mar/15 ]

Ah, you should compile without the -Q flag which suppresses the relevant scons output.

The configure output will look like this (without -Q flag)

scons: Reading SConscript files ...
scons version: 2.3.0
python version: 2 7 6 'final' 0
Checking whether the C++ compiler worksyes
Checking whether the C compiler worksyes
... more lines ...
scons: done reading SConscript files.
scons: Building targets ...

Comment by Judy Han [X] [ 19/Mar/15 ]

Hi Adam,

Here is the full output for the rerun:
%scons --cpppath=/home/jhan/Software/boost/boost_1_55_0 --extrapath=/home/jhan/workspace/MTX/publish_linux/opt/mtx --c++11=on --config=force --sharedclient -Q install-examples
scons version: 2.0.1
python version: 2 6 6 'final' 0
Detected libstdc++ is too old to support C++11 mode

Not sure if that is what your are refering to when you mentioned "full configure output of Scons", if not please let me know.

Since I have multiple compilers installed in my machine and to get the c++11, I do following before I compile my programs:
%scl enable devtoolset-2 "bash"

%which g++
/opt/rh/devtoolset-2/root/usr/bin/g++

%/sbin/ldconfig -p |grep stdc++
libstdc+.so.6 (libc6,x86-64) => /usr/lib64/libstdc+.so.6
libstdc+.so.6 (libc6) => /usr/lib/libstdc+.so.6

%strings /usr/lib/libstdc++.so.6|grep LIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH

Thanks!
Judy

Comment by Adam Midvidy [ 19/Mar/15 ]

Judy,

That is an odd error as GCC 4.8.2 is a fairly modern compiler - I build with the same version. Can you rerun scons with the same options (including c++11=on), but add --config=force. Then can you reply with the full configure output of SCons (everything before "scons: building targets...")

Additionally can you let me know the version of libstdc++ installed on your machine?

Thanks,
Adam

Comment by Judy Han [X] [ 19/Mar/15 ]

Hi Adam,

when I tried --c++11=on option for compiling the driver, I got following error:

scons version: 2.0.1
python version: 2 6 6 'final' 0
Detected libstdc++ is too old to support C++11 mode

This is my g++ version
g++ --version
g++ (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)

Thanks!
Judy

Comment by Adam Midvidy [ 19/Mar/15 ]

Hi Judy,

I think the problem is that you are compiling the driver with c++03, but compiling your application with c++11. As the ABI of libstdc++ changed with the introduction of c++11, it is not possible to link a c++98/03 static library into a c++11 application.

Can you try recompiling the driver with the --c++11=on option, and removing your modification to functional.h?

Thanks,
Adam

Comment by Judy Han [X] [ 19/Mar/15 ]

Hi Adam,
Thanks for the quick response.
Here is the SCons command I used to compile the legacy driver:
scons --cpppath=/home/jhan/Software/boost/boost_1_55_0 --extrapath=/home/jhan/workspace/nonuniqkeywork/publish_linux/opt/mtx --sharedclient -Q install-examples
btw, I had to modify SConstruct as follows:
from: boostLibs = [ "regex", "thread", "system"]
to: boostLibs = [ "regex", "system", "thread"]
otherwise there are compiling errors for library dependancy.

The compiling command for my application is:
g++ mtx_bulk_pool.cpp -std=c++11 -I/home/jhan/Software/mongo-cxx-driver-legacy-1.0.0/src -I/home/jhan/Software/mongo-cxx-driver-legacy-1.0.0/build/linux2/normal -I/home/jhan/workspace/nonuniqkeywork/tools/boost -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_system -lboost_program_options -L/home/jhan/Software/mongo-cxx-driver-legacy-1.0.0/build/install/lib -L/home/jhan/Software/boost/boost_1_55_0/stage/lib

The key flag is -std=c++11, without this flag, it works, but with this flag, it core dumps because it uses std::function instead of boost::function.

Thanks!
Judy

Comment by Adam Midvidy [ 19/Mar/15 ]

Hi Judy -

I am sorry to hear you are having trouble compiling the legacy driver.

Can you tell me the exact SCons invocation you used to compile the legacy driver, as well as the compiler flags used to compile your application?

Thanks,
Adam

Generated at Wed Feb 07 21:59:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.