1

I have created c++ application in Ubuntu machine. I have copied binary to Centos machine. Got error:

/usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found

I decided to check which versions of glibc I have in my machines with help of ldd --version command:

Ubuntu: 2.23
Centos6.9: 2.12

Why CentOS cmplains regarding GLIBCXX_3.4.21, while Ubuntu owns glibc version 2.23?

vico
  • 17,051
  • 45
  • 159
  • 315
  • GLIBC != GLIBCXX. The former is used to version symbols of glibc, the latter for symbols of libstdc++. What this says is that the version of libstdc++ on your CentOS6 system is too old. – Corristo Feb 11 '18 at 12:25
  • You mean GLIBCXX_3.4.21 menas `GLIBC ver. 3.4` and `libstdc++ is ver. 21` ? Then why command `ldd --version` brings `2.12` and `2.23`? – vico Feb 11 '18 at 15:03
  • No, GLIBCXX_3.4.21 doesn't tell you anything about the version of GLIBC. And `ldd --version` only ever tells you the GLIBC version, it simply is not capable to detect which version of libstdc++ you have on your machine. You might want to have a look at http://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html#abi.versioning and https://stackoverflow.com/questions/10354636/how-do-you-find-what-version-of-libstdc-library-is-installed-on-your-linux-mac – Corristo Feb 11 '18 at 15:15

2 Answers2

3

The symbols like GLIBCXX_3.4.21 are generated by the compiler to mark which version of the C++ library that the compilation was used with (in particular, non-inline functions called from header-files & template functions). This is the libstdc++ library, not glibc.

The version that you are looking for is your libstdc++ - and this is one of the interesting problems with C++, the template library tends to change every now and again, so a function may be declared as unsigned int func(), and later someone decides to change it to size_t func(). No difference in 32-bit machines, but for 64-bit machines it DOES make a difference, and using the "wrong" version will lead to problems with the size of the return value.

There are a few different solutions (and this is not a complete list):

  1. Make sure you use the same version of libstdc++ on both machines.
  2. Compile the code on the target machine.
  3. Use static libstdc++
Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
  • 1. Can I have older (Centos) `libstdc++` on my Ubuntu together with current one? How to install it? 3. How to tell my Eclipse to link `libstdc++` statically? – vico Feb 11 '18 at 15:13
  • 1
    1. Probably not two at the same time - or at the very least, you'll have to choose when you compile. Note that the compiler's header files are also coupled to the version of the libstdc++. To link statically with libstdc++, you add `-static -lstdc++ -dynamic` to the linking command (the `-dynamic` isn't strictly needed, but it prevents other libraries specified after this from being linke statically). How you specifically do that in eclipse, I don't really know - it's about 8 years since I last used eclipse, and then with a different build-system than "standard". – Mats Petersson Feb 12 '18 at 07:46
0

This a great - I used the -static option in the link and it solved by problem also.