76

So I'm now desperate in finding a fix for this. I'm compiling a shared library .so in Ubuntu 32 bit (Have tried doing it under Debian and Ubuntu 64 bit, but none worked either)

I keep getting: /usr/lib/libstdc++.so.6: version ``GLIBCXX_3.4.15' not found every time I try to load my plugin.

Here's how I'm getting this error:

  1. Install latest Ubuntu 32 bit
  2. sudo apt-get install build-essential
  3. Compile & load my plugin (.so)

Here are some links which I found and tried, but none worked for me:

(My old question: I somehow got it fixed a few days after posting this question, but I can't remember how exactly I did it)

My Question

Another user with the same problem

And another

I see some people fixed it by moving libstdc++(i think) to some directory and then pointing or linking idk what to that directory, but that just puzzled me.

Anyone know a fix?

(Edit:) - Running: strings /usr/lib/libstdc++.so.6 | grep GLIBC in terminal gives me: strings '/usr/lib/libstdc++.so.6': No such file. Could that be the problem? And if so, how do I install this library?

(Edit2:) Anyone else know of a solution?

(Edit3) Still in need of a solution. is there a way to see on which distro a shared library was compiled on? I know I once compiled this same library a while ago, but can't remember!!

(Edit4) ldd my_lib_.so gives me:

    linux-gate.so.1 =>  (0xb77d7000)
    libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb76c1000)
    libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb76a4000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb74fa000)
    libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb74ce000)
    /lib/ld-linux.so.2 (0xb77d8000)

ldd program_im_loading_so_into gives me:

    linux-gate.so.1 =>  (0xb77d8000)
    libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb77c0000)
    libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb77a5000)
    libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb76bb000)
    libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb768f000)
    libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb7672000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb74c9000)
    /lib/ld-linux.so.2 (0xb77d9000)

running strings /usr/lib/i386-linux-gnu/libstdc++.so.6 | grep GLIBCXX gives me:

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_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_DEBUG_MESSAGE_LENGTH

and finally here's my gcc version:

`gcc version 4.6.4 (Ubuntu/Linaro 4.6.4-1ubuntu1~12.04)`
Community
  • 1
  • 1
user1667191
  • 2,387
  • 6
  • 20
  • 25
  • If you run "nm" against your library, does it show any dependencies on GLIBC3.4.15 ? Did you try to install older libstdc++, built with older glibc version? – Tomasz Myrta Oct 15 '13 at 21:35
  • Hey, I got this while running nm: `U_ZNSt8__detail15_List_node_base7_M_hookEPS0_@@GLIBCXX_3.4.15 U _ZNSt8__detail15_List_node_base9_M_unhookEv@@GLIBCXX_3.4.15` and I just installed all of the libraries(found in the ubuntu app manager) ending with 6.x.x and even installed libstdc++5, but it still not working. Keep getting that same error – user1667191 Oct 15 '13 at 22:18
  • Maybe you have some extra copy of libstdc++ in unusual directory? On debian you should have it in /usr/lib/i386-linux-gnu – Tomasz Myrta Oct 16 '13 at 07:29
  • 1
    Hi. I ran `locate libstdc++.so.6` and got the following: `/usr/lib/i386-linux-gnu/libstdc++.so.6` and `/usr/lib/i386-linux-gnu/libstdc++.so.6.0.18`. I guess that mean that there aren't any other libstdc++ in unusual directories? – user1667191 Oct 17 '13 at 15:24
  • Could you add results of `ldd your.so`, `ldd program_youre_loading_so_into` and `strings /usr/lib/i386-linux-gnu/libstdc++.so.6 | grep GLIBCXX` and your gcc version? – keltar Oct 23 '13 at 08:22
  • 1
    Are you linking your plugin with some object files, that were compiled elsewhere? Also, are you modifying the environment in any way before trying to load the plugin? Are you sure you used the same compiler to compile both plugin and the program which is loading it? What is the output of `LD_DEBUG=all program_im_loading_so_into` ? – Michael Kruglos Oct 30 '13 at 20:52
  • This is a FAQ: http://gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.how_to_set_paths – Jonathan Wakely May 06 '14 at 13:26
  • I got this error when since I installed my own updated gcc compiler for bcftools plugin and used it for bedtools. The thing is that you need to add the `lib64/libstdc++.so.*` from the gcc compiler you installed with to you LD_LIBRARY_PATH before your system gcc at `/usr/lib64`. Unfortunately 90% of SO people think you have admin rights if you are posting on SO. We should start getting in mindset that professional work in the big data world cannot be done on your personal computer – Brian Wiley Jan 20 '21 at 02:01

10 Answers10

49

Link statically to libstdc++ with -static-libstdc++ gcc option.

kerim
  • 2,412
  • 18
  • 16
  • 1
    Other than increasing your binary's size, is there any other downside to this? Perhaps your binary won't benefit from future security updates. Anything else? – Drew Noakes Dec 11 '14 at 16:17
  • @DrewNoakes: you might check out http://stackoverflow.com/questions/13636513/linking-libstdc-statically-any-gotchas – kerim Dec 12 '14 at 12:39
  • 4
    why is this necessary? If gcc can compile with a particular version of libstdc++, why can't the program run using that version on the same machine? – Rik Smith-Unna Jun 04 '15 at 12:58
  • @RikSmith-Unna Don't know. But then, why are we all here? For example because a newer version got installed, the old one removed. – Mayou36 May 02 '22 at 18:52
12

I fixed this issue by installing: sudo apt-get install libstdc++6

In my case, I ran into this issue after installing MongoDB 3.0.1

mongo: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.18' not found (required by mongo)

Shubhamoy
  • 3,718
  • 2
  • 19
  • 24
7

Just install the latest version from nondefault repository:

$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
$ sudo apt-get update
$ sudo apt-get install libstdc++6-4.7-dev
luart
  • 1,383
  • 1
  • 18
  • 25
  • $ add-apt-repository ... command not found (??!! also on Ubuntui (12.04)) – Mawg says reinstate Monica Aug 25 '15 at 06:48
  • 2
    Install python-software-properties and you will have `add-apt-repository`: $ sudo apt-get install software-properties-common python-software-properties http://ubuntuforums.org/showthread.php?t=1971357 – luart Aug 26 '15 at 18:11
4

this problem can be solved by installing the latest libstdc++.

$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
$ sudo apt-get update
$ sudo apt-get install libstdc++6-7-dbg
weiyixie
  • 551
  • 5
  • 6
3

Up above, you mention having compiling your as part of your steps to reproduce, but then below you made an edit saying,

"is there a way to see on which distro a shared library was compiled on?"

Whether or not you compiled this on the same distro, and even a different version of the same distro is an important detail, especially for c++ applications.

Linking to c++ libraries, including libstdc++ can have mixed results, as far as I can tell. Here is a related question about recompiling with different versions of c++.

do we need to recompile libraries with c++11?

Basically, if you compiled against c++ on a different distro (and possibly different gcc version), this may be causing your trouble.

I think you have two options:

  1. Your best bet - recompile your .so if you hadn't compiled it on your current system. If there is a problem with your runtime's system environment, it might even come out in the compile.
  2. Bundle your other compiler's c++ libs along with your application. This may only be viable if it's the same distribution... But it's a useful trick if you rolled your own compiler. You will also have to set and export the LD_LIBRARY_PATH to the path containing your bundled stdc++ libs if you go that route.
Community
  • 1
  • 1
yggdrasil
  • 95
  • 2
  • 7
2

Perhaps the answer to this question is of use here too: how to find libstdc++.so.6: that contain GLIBCXX_3.4.19 for RHEL 6?

curl -O http://ftp.de.debian.org/debian/pool/main/g/gcc-4.7/libstdc++6-4.7-dbg_4.7.2-5_i386.deb
ar -x libstdc++6-4.7-dbg_4.7.2-5_i386.deb && tar xvf data.tar.gz
mkdir backup
cp /usr/lib/libstdc++.so* backup/
cp ./usr/lib/i386-linux-gnu/debug/libstdc++.so.6.0.17 /usr/lib
ln -s libstdc++.so.6.0.17 libstdc++.so.6
Serge Rogatch
  • 13,865
  • 7
  • 86
  • 158
1

If someone has the same issue as I had - make sure that you don't install from the Ubuntu 14.04 repo onto a 12.04 machine - it gives this same error. Reinstalling from the proper repository fixed the issue.

Rob
  • 4,927
  • 4
  • 26
  • 41
  • I was using multiple machines in parallel and didn't realize that one was still on 14.04 while the others were on 15.10. Led to the same problem. Thx. – user2355282 Feb 18 '16 at 16:49
1

This worked for me:

cp <path_to>/libstdc++.so.6 $PWD
./<executable>

This tidbit came from @kerin (comment provided above):

you might check out http://stackoverflow.com/questions/13636513/linking-libstdc-statically-any-gotchas

From that link:

If you put the newer libstdc++.so in the same directory as the executable it will be found at run-time, problem solved.

The error I was getting mentioned that libstdc++.so.6 was coming from /usr/lib64/, but this is not the library I linked against! The message looked like:

<executing_binary>: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by <executing_binary>)

I did verify that LD_LIBRARY_PATH had the directory (and that it was the first path). For some reason at runtime it was still looking at /usr/lib64/libstdc++.so.6.

I took the advice from the article above and copied the libstdc++.so.6 from where I linked into the directory with my executable, ran from there, and it worked!

Sooth
  • 2,834
  • 23
  • 26
0
  • It's important to notice the path of libstdc++ since sudo apt-get install libstdc++6 only update libstdc++ under the path of /usr/lib/x86_64-linux-gnu/.
  • My solution is update libstdc++ by sudo apt-get install libstdc++6 first and then copy the libstdc++ of the newest version to the path where the error occurs. For example: cp /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.32 /usr/local/lib/.
  • Then you need to update the link to the newest version of libstdc++, like: ln -s libstdc++.so.6.0.32 libstdc++.so.6 and ln -s libstdc++.so.6.0.32 libstdc++.so under the path where the error occurs.
-1

Actually, you need to update your repo first, then an upgrade of your Glibc can fix this issue.

Kele Huang
  • 59
  • 2