Is it possible to statically link python into gdb?

Terry Guo flameroc@gmail.com
Wed Jun 25 01:47:00 GMT 2014


On Mon, Jun 23, 2014 at 11:48 PM,  <Paul_Koning@dell.com> wrote:
>
> On Jun 23, 2014, at 9:49 AM, Tim Sander <tim@krieglstein.org> wrote:
>
>> Hi Terry
>>> I am trying to build a gdb with python support which doesn't depend on
>>> system python at all. I can manage to build python into static library
>>> like libpython2.7.a, then I can see that this static library is linked
>>> into gdb. With command ldd, there is no libpython dependence in final
>>> gdb. So far all good. But when run this gdb on another machine, I ran
>>> into below errors and gdb can't be initiated:
>>>
>>> Could not find platform independent libraries <prefix>
>>> Could not find platform dependent libraries <exec_prefix>
>>> Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
>>>
>>> I am working on Ubuntu x86 machines with gdb from master branch and
>>> Python 2.7. Could some one please help me? Thanks in advance.
>> I don't know much about python but might it be that you need the *.py files
>> of PYTHONHOME/lib nevertheless to get a running python interpreter?
>
> I assume you’d need at least a couple, for the standard Python startup machinery to work.  Some of that can be suppressed when Python is involved by a command; I assume this can also be done when Python is embedded.
>
> Note also that a lot of Python modules are not just .py files but also .so files or equivalent.
>
>         paul

Hi folks,

Very appreciate your help. Indeed the python that is statically linked
into gdb needs other modules to run correctly. I now worked around
this issue by following steps:

1). build and install python 2.7 in dynamic way (produced the
libpython2.7.so instead of libpython2.7.a). This python is installed
to my own path instead of system path.
2). unset the variable PYTHONHOME and then export
PYTHONHOME=MY-OWN-PATH:/usr, then configure, build and install gdb.
3). now copy the gdb to other machine, everything works fine. The only
requirement is user will need to install libpython2.7 in their
machine.

I admit that I have to make a compromise here. I am delivering gdb to
my customer and my expectation is that they can use my gdb with python
support no matter there is python in their system and no matter the
version of their installed python. After a lot of attempts, I think I
can't reach my expectation. I guess I have to live with my above
workaround.

BR,
Terry



More information about the Gdb mailing list