http://www.xaprb.com/blog/2007/10/30/ho
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 udf_now_usec.so udf_now_usec.cc
When I tried to execute the above on my OS X box, I got some errors:
$ gcc -fPIC -Wall -I../include -shared -o udf_now_usec.so udf_now_usec.cc i686-apple-darwin8-gcc-4.0.1: unrecognized option '-shared' /usr/bin/ld: Undefined symbols: _main ___gxx_personality_v0</b> 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 udf_now_usec.so udf_now_usec.cc ld: Undefined symbols: ___gxx_personality_v0 /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 $
Hooray..
So in summary: to compile a C++ UDF on OSX, use -dynamiclib instead of -shared
and add -lstdc++ to the compile flags.
Mac / UDF
(Anonymous)
2008-02-26 02:29 am (UTC)
Great info,
thanks!
Roland Bouman
PS: if you are interested, why not join the "UDF repository for MySQL"
http://groups.google.com/group/mysql-udf-r
http://www.mysqludf.org/