{"id":780,"date":"2008-04-14T08:45:53","date_gmt":"2008-04-14T13:45:53","guid":{"rendered":"http:\/\/www.bytebot.net\/blog\/archives\/2008\/04\/14\/compiling-mysql-udfs-on-mac-os-x"},"modified":"2008-04-14T11:28:29","modified_gmt":"2008-04-14T16:28:29","slug":"compiling-mysql-udfs-on-mac-os-x","status":"publish","type":"post","link":"https:\/\/www.bytebot.net\/blog\/archives\/2008\/04\/14\/compiling-mysql-udfs-on-mac-os-x","title":{"rendered":"Compiling MySQL UDFs on Mac OS X"},"content":{"rendered":"<p>Compiling and installing a User Defined Function for MySQL on Mac OS X seems tricky. There are <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/udf-compiling.html\">installation notes<\/a>, but they seem to be sparse on OS X (the comments are clues, though).<\/p>\n<p>I was looking through the tutorial materials for <a href=\"http:\/\/rpbouman.blogspot.com\/\">Roland&#8217;s<\/a> talk, and came up with what I think is the most full-proof way to ensure your UDFs get compiled&#8230;<\/p>\n<p><tt>gcc -Wall -dynamiclib -o udf_lightspeed.dylib -lstdc++ udf_lightspeed.c<\/tt><\/p>\n<p>The above will compile just fine, but MySQL will give you an interesting error saying &#8220;no suitable image found&#8221;. Its the infamous Error 1126.<\/p>\n<p>Upon further poking, it seemed like the following should work:<br \/>\n<tt>gcc -Wall -dynamiclib -o udf_lightspeed.dylib -lstdc++ -lc -I`\/usr\/local\/mysql\/bin\/mysql_config --cflags` udf_lightspeed.c<\/tt><\/p>\n<p>And it does. MySQL loads the UDF just fine. But sometimes, you get linker errors, which can be annoying.<\/p>\n<p>So, the full-proof solution to compiling UDFs on OS X, Leopard 10.5? A two-step process:<br \/>\n<tt>gcc -c `\/usr\/local\/mysql\/bin\/mysql_config --cflags` udf_lightspeed.c<br \/>\nlibtool -dynamic -o udf_lightspeed.so udf_lightspeed.o -lc<\/tt><\/p>\n<p>Feel free to add <tt>-O2<\/tt> as an option to GCC. One day I might talk about the amazing <tt>mysql_config<\/tt> (use it! Read the <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/mysql-config.html\">documentation<\/a>, in the meantime.)<\/p>\n<p>Remember, once you&#8217;ve your your .dylib, to move it to your plugin_dir (find it by doing <tt>SHOW VARIABLES LIKE 'plugin_dir';<\/tt>). Also note that on OS X, it doesn&#8217;t matter if the extension is .dylib or .so &#8211; either one will do.<\/p>\n<p>Happy UDF usage!<\/p>\n<p><strong>Update:<\/strong> As a reader points out in the comments, probably the easiest way, in a one-step process, is to use the <tt>bundle_loader<\/tt>. <tt>gcc -Wall -bundle -bundle_loader \/usr\/local\/mysql\/bin\/mysqld -o udf_return_values.so `\/usr\/local\/mysql\/bin\/mysql_config \u2014cflags` udf_return_values.c<\/tt> works a charm.<\/p>\n<p>Technorati Tags: <a class=\"performancingtags\" rel=\"tag\" href=\"http:\/\/technorati.com\/tag\/udf\">udf<\/a>, <a class=\"performancingtags\" rel=\"tag\" href=\"http:\/\/technorati.com\/tag\/mysql\">mysql<\/a>, <a class=\"performancingtags\" rel=\"tag\" href=\"http:\/\/technorati.com\/tag\/compiling\">compiling<\/a>, <a class=\"performancingtags\" rel=\"tag\" href=\"http:\/\/technorati.com\/tag\/macosx\">macosx<\/a>, <a class=\"performancingtags\" rel=\"tag\" href=\"http:\/\/technorati.com\/tag\/leopard\">leopard<\/a>, <a class=\"performancingtags\" rel=\"tag\" href=\"http:\/\/technorati.com\/tag\/libtool\">libtool<\/a>, <a class=\"performancingtags\" rel=\"tag\" href=\"http:\/\/technorati.com\/tag\/mysql_config\">mysql_config<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Compiling and installing a User Defined Function for MySQL on Mac OS X seems tricky. There are installation notes, but they seem to be sparse on OS X (the comments are clues, though). I was looking through the tutorial materials for Roland&#8217;s talk, and came up with what I think is the most full-proof way [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[23],"tags":[],"class_list":["post-780","post","type-post","status-publish","format-standard","hentry","category-mysql"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/p4vJD-cA","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"amp_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts\/780","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/comments?post=780"}],"version-history":[{"count":0,"href":"https:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts\/780\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/media?parent=780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/categories?post=780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/tags?post=780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}