#284 ImportError when using MySQLdb in embedded python

open
Andy Dustman
MySQLdb (285)
5
2012-09-19
2009-05-21
Jonas Meurer
No

Package: python-mysqldb
Version: 1.2.2-7

On Debian GNU/Linux 5.0 (lenny). Python 2.5.2-3.

When python is embedded in a shared library (in my case a plugin), the
_mysql.so component of MySQLdb fails to load, due to this error:

Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: /var/lib/python-support/python2.5/_mysql.so: undefined
symbol: PyExc_ImportError

Discovered while trying to use the ida2sql.py script within IDAPython.

A simple example program is attached demonstrating the problem clearly,
this sample program also demonstrates a work-around, by setting the
RTLD_GLOBAL flag when loading the shared library, the necessary python
symbols are exported for _mysql.so and it loads correctly. Unfortunately
this isn't possible in my situation since IDA Pro is not open source,
and in general I think it's unwise for an application to export all the
symbols from any plugins it may load as there is a high probability of a
symbol collision.

I have also been able to work around this issue by re-linking _mysql.so
and including a direct dependancy on libpython2.5.so.1.0. This may not
be the right thing to do when using MySQLdb from the standard python
interpreter however?

you can compile

Discussion

  • Jonas Meurer
    Jonas Meurer
    2009-05-21

    pymain.c

     
    Attachments
  • Jonas Meurer
    Jonas Meurer
    2009-05-21

    pysql.c

     
    Attachments
  • Jonas Meurer
    Jonas Meurer
    2009-05-21

    makefile

     
    Attachments