I spent quite a bit of time working on getting gdb (7.9) to work with Python (2.7). In the end everything worked rather well. However, there are a bunch of things that you have to get right. The key point is that the gdb configure script tries to compile a small C program that looks like this.
#include "Python.h"
int
main ()
{
Py_Initialize ();
;
return 0;
}
If this program won't compile, then Python support won't be built. For this program to compile, the Python.h include file must be found in /usr/include/python2.7
. This file will only exist if the python-devel
package is installed. On my system (redhat), the command for installing this package is sudo yum install python-devel
.
However, that's not enough to get Python installed. Before the configure script tries to compile the C program, it gets various options from python-config.py
. If these options aren't correct, then the C program won't compile. On my system, python-config.py
returned the options below.
-lpthread -ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic
These options didn't cause any problems in my environment. Other folks have had problems with the options returned from python-config.py
and have made changes to python-config.py
to resolve these problems. On my system the complete compile command was
gcc -o conftest -g -O2 -I/usr/include/python2.7 -I/usr/include/python2.7 \
conftest.c -ldl -lncurses -lz -lm -ldl -lpthread -ldl -lutil -lm \
-lpython2.7 -Xlinker -export-dynamic
This compile command completed without any errors as soon as I installed python-devel
. Note you don't have to manually enter the gcc
command. I did run the gcc
command several times to make sure everything was correct. Normally, the configure script will run the
compiler for you. Also note that to get the overall gdb install process to complete, makeinfo
also had to be installed. The command for installing makeinfo was sudo yum install texinfo
.
Overall, the correct set of steps seems to be
Install python-devel
Install texinfo
Download the gdb source and gunzip it and untar it.
cd
to the gdb-7.9
directory with the configure
file.
-
./configure --prefix=/usr --with-python
make
sudo make install
It should be possible to get gdb to work with Python 3. The various gdb scripts and install programs mention Python 3 in many, many places. However, the correct procedure for installing gdb with Python 3 is unknown to me at this point.
sh -x ./configure --with-python
and keep the output. Look for howconfigure
handles--with-*
, and look at the Makefile to see how it checks forpython2.7
. Could it need thepython2.7 source
?sudo apt-get install python-dev