Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#243 Static link still depends on shared library (Linux)

MySQLdb-1.3
open
Andy Dustman
MySQLdb (285)
5
2012-09-19
2008-01-23
Greg Ward
No

I'm trying to build MySQL-python 1.2.2 statically on Red Hat Enterprise Linux 3.0. I edited site.cfg and set "static = True". When I build with this command:

$ python2.5 setup.py build_ext -f

the link command ends up being

gcc -pthread -shared build/temp.linux-i686-2.5/_mysql.o /usr/lib/mysql/libmysqlclient.a -L/usr/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -o build/lib.linux-i686-2.5/_mysql.so

Note that it's linking with libmysqlclient.a (good) as well as "-lmysql" (bad). The resulting .so file appears to be both statically linked (it's 309k rather than ~112k) and dynamically linked (ldd reports that it depends on /usr/lib/mysql/libmysqlclient.so.10).

This is with a local build of Python 2.5.1 and a local build of gcc 3.2.1, all running on RHEL 3.0 using Red Hat's package of the MySQL client libs (mysql-3.23.58-16.RHEL3.1). Yes, I know this is mostly ancient code; we're still stuck with this as our basic build platform for reasons I won't elaborate here.

Discussion

  • Greg Ward
    Greg Ward
    2008-01-23

    patch for setup_posix.py

     
    Attachments
  • Greg Ward
    Greg Ward
    2008-01-23

    Logged In: YES
    user_id=14422
    Originator: YES

    Luckily the fix appears really simple: just remove the MySQL client lib from the 'libraries' list, which means distutils will not generate the "-lmysql" option -- the explicit "libmysql.a" in extra_objects replaces it completely. Patch attached.

    File Added: sf1878264.patch

     
  • Greg Ward
    Greg Ward
    2008-01-23

    Logged In: YES
    user_id=14422
    Originator: YES

    Note that my patch assumes library_dirs[0] is the MySQL library dir, which bug #1834305 (static link on FreeBSD) shows is not the case.

     
  • Andy Dustman
    Andy Dustman
    2009-03-11

    Probably not fixing for 1.2. 1.3/2.0 will be much more flexible about being able to pick which driver to use at runtime.