17

When I use gdb to debug my C++ program with segmentation fault, I come with this error in gdb.

Traceback (most recent call last): File "/usr/share/gdb/auto-load/usr/lib/x86_64-linux- gnu/libstdc++.so.6.0.19-gdb.py", line 63, in from libstdcxx.v6.printers import register_libstdcxx_printers ImportError: No module named 'libstdcxx'

I am using Gdb 7.7.1 and g++ version 4.8.4. I have googled around but haven't get answers. Can any one solve my error? Thank you very much.

toantruong
  • 464
  • 1
  • 8
  • 16
  • 1
    First googled.... [http://askubuntu.com/questions/345873/gdb-crashes-with-importerror-no-module-named-libstdcxx-v6-printers](http://askubuntu.com/questions/345873/gdb-crashes-with-importerror-no-module-named-libstdcxx-v6-printers) – LPs Sep 04 '15 at 06:36

5 Answers5

21

This is a bug in /usr/lib/debug/usr/lib/$triple/libstdc++.so.6.0.18-gdb.py; When you start gdb, please enter:

python sys.path.append("/usr/share/gcc-4.8/python");

adairjun
  • 325
  • 4
  • 16
  • 1
    I suggest to read the [answer](https://stackoverflow.com/a/34350497/4123703) from [cloudrain21](https://stackoverflow.com/users/5195935/cloudrain21) which is more descriptive. – Louis Go Jan 17 '22 at 09:06
14

I encountered this error during using gdb in emacs. (in docker container - ubuntu) I tried it like below and worked well.

(1) open libstdc++.so.x.x.x-gdb.py

sh> sudo vi /usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19-gdb.py

(2) modify that file(libstdc++.so.x.x.x-gdb.py ) like below.

import sys 
import gdb 
import os
import os.path

pythondir = '/usr/share/gcc-4.8/python'
libdir = '/usr/lib/x86_64-linux-gnu'

sys.path.append(pythondir)    <-- add this code

(3) execute gdb again

Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...done.
(gdb) b main
Breakpoint 1 at 0x400ae9: file vector7.cpp, line 7.
(gdb) r
Starting program: /home/dplee/work/study_room/c++/a.out 

Breakpoint 1, main () at vector7.cpp:7
7       vector<int> v(10);
(gdb) list
2   #include <vector>
3   using namespace std;
4   
5   int main()
6   {
7       vector<int> v(10);
8       int num = 0;
9   
10      for(auto& i : v)
11      {
(gdb) 
cloudrain21
  • 649
  • 5
  • 17
1

I picked libstdcxx from gcc installation path, and this error went away for me.

sys.path.insert(0, '/global/freeware/Linux/RHEL6/gcc-6.2.0/share/gcc-6.2.0/python')
chevybow
  • 9,959
  • 6
  • 24
  • 39
Navnish Garg
  • 103
  • 7
1

For those who do not have sudo privilege, setting PYTHONPATH env before running gdb will work:

export PYTHONPATH="/usr/share/gcc-<your_version>/python:${PYTHONPATH}"
s417-lama
  • 83
  • 4
0

If you used sudo to start the gdb, make sure you have the PATH correct.

Try this sudo PATH=$PATH gdb ...

Ken H
  • 601
  • 8
  • 6