Dan's Website

Ramblings of a Disaffected Geek

 
Home > Software > Compiling UDFs for 64 bit MySQL on OS X 10.5
Compiling UDFs for 64 bit MySQL on OS X 10.5

Getting 64-bit MySQL UDFs working on a Leopard desktop


I'd built some UDFs before by hand, but every time I moved to a new platform getting them working proved a real chore.

I've simplified the process somewhat by using Hartmut Holzgraefe's CodeGen_MySQL_UDF package, which takes 99% of the boilerplate code out of building the UDF and makes things much more cross-platform compatible, thanks to making use of standard tools like libtool and autoconf.

Getting all of this working on a Mac presents some fun tribulations in itself - especially if you've installed the 64 bit version of MySQL. By default, compiling via the command line seems to generate 32 bit libraries, which the 64 bit server won't work with. So it took much Googling and experimenting before I figured out how to make it all work together.

What follows is my command line dump to get a moving average UDF linked into MySQL 5.1.30 64 bit on an OS X 10.5 desktop. You'll need MacPorts installed. Here goes:


sudo pear install --alldeps CodeGen_MySQL_UDF-0.9.7dev   # Use this version - 0.9.8 beta version doesn't work at least on my platform

sudo port install libtool libtool-devel

sudo ln -s /opt/local/bin/glibtoolize /usr/local/bin/libtoolize  # CodeGen uses libtoolize, but the port above installs 'glibtoolize'.  Does the same thing, so just symlink it to make it work

udf-gen mav.xml

cd mav

# Here's where we set up the 64 bit build environment
export MACOSX_DEPLOYMENT_TARGET=10.5 

export CFLAGS="-arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch x86_64 -g -Os -pipe" CXXFLAGS="-arch x86_64 -g -Os -pipe" 
LDFLAGS="-arch x86_64 -bind_at_load" 

./configure --with-mysql=/usr/local/mysql-5.1.30-osx10.5-x86_64/

# Build it
make clean && make

# Create the symlink and install it in MySQL's plugins dir

libtool -dynamic -o mav.so mav_la-mav.o -lc && sudo cp mav.so /usr/local/mysql-5.1.30-osx10.5-x86_64/lib/plugin/

# Load it
mysql> create function mav returns float soname 'mav.so';
There are lots of good example xml files for CodeGen at the project repository.
Comments
Add New Search
Write comment
Name:
Email:
 
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Please input the anti-spam code that you can read in the image.

3.23 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."