7

How can I tell if a certain c++ library was linked using c++11 standard?

kroiz
  • 1,722
  • 1
  • 27
  • 43
  • I am asking because when building mongodb C++ legacy driver one have to make sure that the existing boost is built using the same C++ standard as mongodb driver - which is C++11 – kroiz Oct 29 '15 at 06:05
  • so, you want to know the compiler version as to what compiler version was the binary built with?? – basav Oct 29 '15 at 06:13
  • I am not sure how to get what you want, but there is a way to find the version of the compiler. (http://stackoverflow.com/questions/2387040/how-to-retrieve-the-gcc-version-used-to-compile-a-given-elf-executable). You can create a minimum compiler version required list, and sort of achieve that. But again, if -std=c++11 was used while compiling, is not answered as of now. – badola Oct 29 '15 at 06:21
  • Not the compiler version as in whether it was g++ 4.4 or g++ 4 but rather if the compiling was done with a flag for C++11. – kroiz Oct 29 '15 at 06:22
  • 1
    *"one have to make sure that the existing boost is built using the same C++ standard"* - not necessarily... there's no Standard-mandated break in the ABI, so it just depends on whether the specific versions of compilers you've used - with whatever flags you've specified - have breaks. If I were you, I'd just try it and see if it works. I certainly link a mix of objects compiled with and without -std=c++11 - but all with the same compiler version - against boost and have seen no issues. – Tony Delroy Oct 29 '15 at 06:27
  • How do I know that it works? Is Initializing the library enough or do I need full coverage? Beside there is a comment in the mongo-cxx-driver wiki that says that boost package on ubuntu is not using C++11 and I think it is wrong and I want to prove to the maintainer that it is wrong so he will fix the wiki because it is misleading developers to use the wrong build flags and spend hours figuring out what is wrong. For me mongo-cxx-driver started working only once I built mongo-cxx-driver with the C++11 flag but that could be incidental. right? – kroiz Oct 29 '15 at 06:35
  • *"boost package on ubuntu is not using C++11"* - that may be true for some or all versions of Ubuntu, but it probably means the boost libraries use other hackier and/or less efficient methods internally to provide their promised functionality... it shouldn't make a visible difference to a client program, except for some rare boost functionality that simply isn't supported for C++03, and even then I'd expect compilation or linking errors not runtime. I have no idea about your mongo cxx driver... sorry. – Tony Delroy Oct 29 '15 at 06:54

1 Answers1

3

An elf binary would by default contain the signature of compiler version used.

Now, with regards to compiler flags used, If -frecord-gcc-switches is used at compile time, then, you can find the signature in ELF executable.

 g++ -frecord-gcc-switches -std=c++0x trial.cpp
readelf -p .GCC.command.line a.out

String dump of section '.GCC.command.line':

  [     0]  -imultilib . [     d]  -imultiarch x86_64-linux-gnu   [    2a]  -D_GNU_SOURCE   [ 38]  trial.cpp   [    42]  -mtune=generic   [    51]  -march=x86-64  [    5f]  -std=c++0x   [    6a]  -frecord-gcc-switches   [    80]   
-fstack-protector
basav
  • 1,475
  • 12
  • 20
  • How do I get that string dump please? – kroiz Oct 29 '15 at 06:51
  • using hexedit on libboost_system.so.1.54.0 I get: ibboost_system.so.1.54.0.GCC_3.0.GLIBC_2.4.GLIBC_2.2.5.GLIBCXX_3.4.CXXABI_1.3 maybe the ABI number could help to figure compatibility between boost and mongo driver. – kroiz Oct 29 '15 at 07:01
  • 2
    readelf -p .GCC.command.line a.out..this should give you string dump – basav Oct 29 '15 at 07:09
  • 1
    you could also use strings utility...strings a.out|grep "xyz" – basav Oct 29 '15 at 07:10
  • These yielded no result, I guess the boost package I have, was not compiled using -frecord-gcc-switches. – kroiz Oct 29 '15 at 07:54
  • you can build boost package i guess, if you have the time for it – basav Oct 29 '15 at 08:19
  • Due the lack of a better answer I assume that this is the best we can get - Selecting this as the accepted answer. – kroiz Nov 01 '15 at 06:57