{"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":"http:\/\/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<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-email\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-email sd-button share-icon\" href=\"mailto:?subject=%5BShared%20Post%5D%20Compiling%20MySQL%20UDFs%20on%20Mac%20OS%20X&body=http%3A%2F%2Fwww.bytebot.net%2Fblog%2Farchives%2F2008%2F04%2F14%2Fcompiling-mysql-udfs-on-mac-os-x&share=email\" target=\"_blank\" title=\"Click to email a link to a friend\" data-email-share-error-title=\"Do you have email set up?\" data-email-share-error-text=\"If you&#039;re having problems sharing via email, you might not have email set up for your browser. You may need to create a new email yourself.\" data-email-share-nonce=\"1fcec8f32e\" data-email-share-track-url=\"http:\/\/www.bytebot.net\/blog\/archives\/2008\/04\/14\/compiling-mysql-udfs-on-mac-os-x?share=email\"><span>Email<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-780\" class=\"share-facebook sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2008\/04\/14\/compiling-mysql-udfs-on-mac-os-x?share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\" ><span>Facebook<\/span><\/a><\/li><li class=\"share-linkedin\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-linkedin-780\" class=\"share-linkedin sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2008\/04\/14\/compiling-mysql-udfs-on-mac-os-x?share=linkedin\" target=\"_blank\" title=\"Click to share on LinkedIn\" ><span>LinkedIn<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-780\" class=\"share-twitter sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2008\/04\/14\/compiling-mysql-udfs-on-mac-os-x?share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\" ><span>Twitter<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","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<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-email\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-email sd-button share-icon\" href=\"mailto:?subject=%5BShared%20Post%5D%20Compiling%20MySQL%20UDFs%20on%20Mac%20OS%20X&body=http%3A%2F%2Fwww.bytebot.net%2Fblog%2Farchives%2F2008%2F04%2F14%2Fcompiling-mysql-udfs-on-mac-os-x&share=email\" target=\"_blank\" title=\"Click to email a link to a friend\" data-email-share-error-title=\"Do you have email set up?\" data-email-share-error-text=\"If you&#039;re having problems sharing via email, you might not have email set up for your browser. You may need to create a new email yourself.\" data-email-share-nonce=\"1fcec8f32e\" data-email-share-track-url=\"http:\/\/www.bytebot.net\/blog\/archives\/2008\/04\/14\/compiling-mysql-udfs-on-mac-os-x?share=email\"><span>Email<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-780\" class=\"share-facebook sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2008\/04\/14\/compiling-mysql-udfs-on-mac-os-x?share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\" ><span>Facebook<\/span><\/a><\/li><li class=\"share-linkedin\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-linkedin-780\" class=\"share-linkedin sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2008\/04\/14\/compiling-mysql-udfs-on-mac-os-x?share=linkedin\" target=\"_blank\" title=\"Click to share on LinkedIn\" ><span>LinkedIn<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-780\" class=\"share-twitter sd-button share-icon\" href=\"http:\/\/www.bytebot.net\/blog\/archives\/2008\/04\/14\/compiling-mysql-udfs-on-mac-os-x?share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\" ><span>Twitter<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_options":[]},"categories":[23],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4vJD-cA","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":927,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2008\/08\/08\/howto-mysql-connectorc-on-mac-os-x","url_meta":{"origin":780,"position":0},"title":"HOWTO: MySQL Connector\/C++ on Mac OS X","date":"8\/8\/2008","format":false,"excerpt":"Excited with the release of the MySQL Connector\/C++, I thought I'd get it going on Mac OS X. You'll first hit the problem that Mac OS X doesn't come with CMake. So you'll have to download it from the site - there's a warning there that the .dmg installer only\u2026","rel":"","context":"In &quot;MySQL&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":781,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2008\/04\/14\/my-favourite-bugfix-in-mysql-5124-rc","url_meta":{"origin":780,"position":1},"title":"My favourite bugfix in MySQL 5.1.24-rc","date":"14\/4\/2008","format":false,"excerpt":"I've been using MySQL 5.1 a lot more of late. Also, as of about a month ago, I'm now a Mac OS X user, so tend to use MySQL on OS X Leopard 10.5 a lot more for testing. I've found a rather annoying bug (in 5.1.23-rc) that is fixed\u2026","rel":"","context":"In &quot;MySQL&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":666,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2007\/11\/16\/mysql-on-leopard-os-x-105","url_meta":{"origin":780,"position":2},"title":"MySQL on Leopard (OS X 10.5)","date":"16\/11\/2007","format":false,"excerpt":"Use MySQL? On Leopard\/OS X 10.5? Yes, the current available packages from dev.mysql.com don't work very well. I track \"mysql\" on Twitter, and boy, are there heaps of complaints.So its nice to see, Dan Benjamin, a member of the MySQL community, stepping up, and creating the amazing Installing MySQL on\u2026","rel":"","context":"In &quot;MySQL&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1054,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2008\/09\/21\/workbench-511-alpha-on-fedora-9","url_meta":{"origin":780,"position":3},"title":"workbench-5.1.1-alpha on Fedora 9","date":"21\/9\/2008","format":false,"excerpt":"So, you want to compile Workbench for Linux, on Fedora 9. You need to install the following packages: autoconf automake libtool libzip-devel libxml2-devel libsigc++20-devel libglade2-devel gtkmm24-devel mesa-libGLU-devel mysql-libs mysql mysql-devel uuid-devel lua-devel glitz-devel glitz-glx-devel pixman-devel pcre-devel libgnome-devel gtk+-devel pango-devel cairo I feel I'm being too liberal with dependencies, but I'm\u2026","rel":"","context":"In &quot;MySQL&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":764,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2008\/04\/06\/mysql-on-leopard-os-x-105-prefpane-fixed","url_meta":{"origin":780,"position":4},"title":"MySQL on Leopard OS X 10.5 PrefPane fixed!","date":"6\/4\/2008","format":false,"excerpt":"A few months ago, I wrote about the issues you will face with installing MySQL on OS X 10.5, Leopard. I am pleased to inform everyone, that this problem has been fixed!The bug in question, mysql#28854, clearly stated that the problem was with the PrefPane. On Valentine's Day 2008, Alfredo\u2026","rel":"","context":"In &quot;MySQL&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2708,"url":"http:\/\/www.bytebot.net\/blog\/archives\/2013\/04\/30\/testing-fedora-19","url_meta":{"origin":780,"position":5},"title":"Testing Fedora 19","date":"30\/4\/2013","format":false,"excerpt":"Today I downloaded Fedora 19 alpha to give it a spin. Some quick notes. You can get MySQL by asking for the package community-mysql-server. This is 5.5.31. If you ask for stock \"mysql\" (i.e. yum install mysql-server), you automatically get MariaDB 5.5.30 (mariadb-server). Fedora 19 runs systemd, so there is\u2026","rel":"","context":"In &quot;MariaDB&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"amp_enabled":true,"_links":{"self":[{"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts\/780"}],"collection":[{"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/comments?post=780"}],"version-history":[{"count":0,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/posts\/780\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/media?parent=780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/categories?post=780"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.bytebot.net\/blog\/wp-json\/wp\/v2\/tags?post=780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}