My SQL Dump

MySQL musings by a self professed MySQL Geek

Previous Entry Share Next Entry
How to compile a C++ MySQL UDF on OSX 10.4
Recently, I came upon Baron Swartz's (xaprb's) great now_usec UDF:

I use an Intel Macbook Pro for my primary development environment. GCC on OS X has some interesting quirks. Usually to compile a UDF on GNU/Linux I use the following command line:

gcc -fPIC -Wall -I/usr/include/mysql -shared -o

When I tried to execute the above on my OS X box, I got some errors:

$ gcc -fPIC -Wall -I../include -shared -o
i686-apple-darwin8-gcc-4.0.1: unrecognized option '-shared'
/usr/bin/ld: Undefined symbols:
collect2: ld returned 1 exit status

The first error had me particularly flummoxed for a few moments, as -shared is supposed to work to create shared objects :) It turns out that OSX uses -dynamiclib instead of shared. I have no idea why.

$ gcc -fPIC -Wall -I../include -dynamiclib -o
ld: Undefined symbols:
/usr/bin/libtool: internal link edit command failed

Okay, thats better, but there is still an undefined symbol... Well, it turns out after some digging that ___gxx_personality_v0 is defined in the stdc++ library..

Adding -lstdc++ to the compile should fix that...

$ gcc -fPIC -Wall -I../include -dynamiclib -lstdc++ -o 


So in summary: to compile a C++ UDF on OSX, use -dynamiclib instead of -shared
and add -lstdc++ to the compile flags.

  • 1

Mac / UDF


Great info,


Roland Bouman

PS: if you are interested, why not join the "UDF repository for MySQL"

  • 1

Log in