MySQL 64bit, Perl 32bit and OS X Leopard

This is a little tip on how to get Perl(32bit) working with a 64bit version of MySQL on OS X Leopard.

I was working on a small project today that required MySQL 5.067 and I opted to do it in Perl 5.10. You may remember a post that I put up in August describing how to compile MySQL 64 bit for OS X Leopard. Well, since then I also compiled and installed Perl 5.10 (not replacing Apple’s system install of Perl). I wanted to take advantage of some of the Perl 6 features that have been backported to Perl 5.10 (the first Perl release in two years).

Back to today’s project, I decided to use the awesome Class::DBI Perl module to do my little project. I wrote all my code and began to run it in the perl debugger and realized that I need to install the DBD::mysql module. During the installation process for DBD::mysql, the Perl module is compiled using the mysql libraries and header files. Compilation wasn’t a problem. It’s when we got to the ‘make test’ step that all hell broke loose.

To cut a very long story short, I kept getting the error below:


# Failed test 'use DBD::mysql;'
# at t/00base.t line 21.
# Tried to use 'DBD::mysql'.
# Error: Can't find 'boot_DBD__mysql' symbol in /Users/pankaj/.cpanplus/5.10.0/build/DBD-mysql-4.010/blib/arch/auto/DBD/mysql/mysql.bundle

I dug around a bit and decided to run the installation manually. The problem here has to do with compiler flags that were used for mysql. MySQL was compiled as a 64 bit Leopard binary. However, Perl 5.10 was compiled as a 32bit binary because many Perl modules don’t support 64 bit out of the box.

To solve the problem, I had to recompile the mysql client libraries:


--($:~/src/mysql-5.0.67)-- export ARCHFLAGS="-arch i386"
--($:~/src/mysql-5.0.67)-- CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
-fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql.32 --without-server --with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile --enable-shared
--($:~/src/mysql-5.0.67)-- make
--($:~/src/mysql-5.0.67)-- make test
--($:~/src/mysql-5.0.67)-- sudo make install

Once the mysql client libs were done compiling and installed into /usr/local/mysql.32, I changed my PATH to ensure that the newly compiled mysql libraries and binaries were picked up before anything else.


export PATH=/usr/local/mysql.32/bin:${PATH}

Once that was done, I went back to my DBD::mysql source directory and built it using the following commands:


--($:~/src/DBD-mysql-4.010)-- perl Makefile.PL --libs="-L/usr/local/mysql.32/lib/mysql -lmysqlclient -lz -lm" --cflags="-I/usr/local/mysql.32/include/mysql"
--($:~/src/DBD-mysql-4.010)-- make
--($:~/src/DBD-mysql-4.010)-- make test
--($:~/src/DBD-mysql-4.010)-- sudo make install

This time, make test ran beautifully with a few minor exceptions because I didn’t actually give it a mysql db to connect to.

The mysql 32bit client can easily connect to the 64 bit server. Perl, Class:DBI are now very happy and the application is running as planned.
[ad#post]


Posted

in

, , , , ,

by