Compiling MySQL-python on Solaris 10

By Alasdair Lumsden on 6 Mar 2009

This one can be a bit of a nightmare on Solaris, due to typical Solaris complications. There are two key things to watch out for.

First thing to watch out for, is that MySQL-python includes both pyconfig.h and my_config.h, both of which on Solaris may include SIZEOF_ definitions. If you’re using Sun Web Stack 1.4, the my_config.h file is for 64bit, but we’ll no doubt be compiling as 32bit. Our recommendation is to compile up your own mysql client library and link against this (see my previous post about compiling things against the Sun Web Stack 1.4 MySQL).

compiling-mysql-python-on-solaris

The second thing to watch out for is that Python and MySQL both record the compiler options they were compiled with. For example, -fPIC, -Wall, etc. MySQL-python blindly passes these to whatever compiler you’re using. These may be the wrong arguments, generating all sorts of warnings and/or errors. Ones like these:

# MySQL compiled with Sun Studio, Python compiled with gcc, we're compiling with Sun Studio:
building '_mysql' extension
creating build/temp.solaris-2.10-i86pc-2.5
creating build/temp.solaris-2.10-i86pc-2.5/src
/opt/SUNWspro/bin/cc -OPT:Olimit=0 -DNDEBUG -O -Kpic -Dversion_info=(1, 3, 0, 'f                                                         inal', 0) -D__version__=1.3.0 -I/opt/webstack/mysql/include/mysql -I/opt/python2                                                         .5/include/python2.5 -c src/mysqlmod.c -o build/temp.solaris-2.10-i86pc-2.5/src/                                                         mysqlmod.o -xarch=386 -xchip=pentium -xspace -xildoff -xc99=all -xnorunpath -m32                                                          -DBIG_TABLES -DHAVE_RWLOCK_T
cc: Warning: illegal option -OPT:Olimit=0
"/usr/include/sys/feature_tests.h", line 332: #error: "Compiler or options inval                                                         id for pre-UNIX 03 X/Open applications  and pre-2001 POSIX applications"
cc: acomp failed for src/mysqlmod.c
error: command '/opt/SUNWspro/bin/cc' failed with exit status 2

# MySQL compiled with gcc, Python compiled with Sun Studio, we're compiling with gcc:
building '_mysql' extension
creating build/temp.solaris-2.10-i86pc-2.5
creating build/temp.solaris-2.10-i86pc-2.5/src
gcc -OPT:Olimit=0 -DNDEBUG -O -Kpic -Dversion_info=(1, 3, 0, 'final', 0) -D__version__=1.3.0 -I/opt/ec/mysql_client/include/mysql -I/opt/python2.5/include/python2.5 -c src/mysqlmod.c -o build/temp.solaris-2.10-i86pc-2.5/src/mysqlmod.o -DHAVE_RWLOCK_T
gcc: unrecognized option `-Kpic'
cc1: error: invalid option argument `-OPT:Olimit=0'

# etc, there are quite a few combinations here

Our solution to this was to find out what your python is compiled with (Sun Studio or gcc) by looking in the “lib/python*/config/Makefile” file (relative to where python is installed), compile up your own MySQL client library using the same compiler, then compile MySQL-python with that same compiler.

Don’t forget to set the LDFLAGS environment variable with -L and -R paths to your MySQL client library path and Python library path, so that MySQL-python can find the libraries when it compiles.