Building GDB with a cross-compiler, including Python support

N.B. Corrections and improvements to these instructions are welcome!

Cross-compiling a program that links with Python is problematic. The right way involves running python-config.py, but in a cross-compilation build you don't necessarily have a python to run, and the config for the host's python is wrong.

Here is one solution. Basically, it involves a shell script that returns the same results that python-config.py would, and you pass that as the argument to --with-python.

Example:

bash$ cat $HOME/my-python-for-config
#! /bin/sh

if [ $# -ne 2 ]
then
        echo "Bad # args.  Blech!" >&2
        exit 1
fi

# The first argument is the path to python-config.py, ignore it.

case "$2" in
--includes) echo "-I/usr/include/python2.6" ;;
--ldflags) echo "-L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm -lpython2.6" ;;
--exec-prefix) echo "/usr" ;;
*) echo "Bad arg $2.  Blech!" >&2 ; exit 1 ;;
esac

exit 0
bash$ chmod +x $HOME/my-python-for-config
bash$ ./configure --with-python=$HOME/my-python-for-config [...]
[...]

You need to provide your own values for --includes, --ldflags, --exec-prefix. The values shown above are obviously for a native build (but useful to exercise the script :)). The best way to get the needed values is if you have python installed on the target system and run python-config.py there.

Example:

bash$ cd $src/gdb
bash$ python python/python-config.py --includes
[record this output]
bash$ python python/python-config.py --ldflags
[record this output]
bash$ python python/python-config.py --exec-prefix
[record this output]

or

bash$ python-config --includes
[record this output]
bash$ python-config --ldflags
[record this output]
bash$ python-config --exec-prefix
[record this output]

None: CrossCompilingWithPythonSupport (last edited 2012-10-02 15:38:10 by DougEvans)

All content (C) 2008 Free Software Foundation. For terms of use, redistribution, and modification, please see the WikiLicense page.