Ruby, Leopard and gems
In case you have been sleeping in the same cave as Osama Bin Laden, Apple’s new OS X Leopard includes Ruby as a first-class language.
But Apple’s effort to make the language and all it’s extensions universal binaries can cause you some trouble when installing gems that require compilation.
If you’re installing on an Intel machine and see an error like “ld: symbol(s) not found for architecture ppc”, you probably are installing a gem that requires an external library, for which you only have the i386 version. This is a typical situation when installing mysql (as noted in the troubleshooting page of the MacOSForge wiki for Ruby).
After trying several variations, I came out with this solution:
If your installation command was
sudo gem install mysql
you need to run it as
sudo bash -c "ARCHFLAGS='-arch i386' gem install mysql"
sudo env ARCHFLAGS="-arch i386" gem install mysql
There you go… that should be all you need to install the mysql gem on Leopard against MySQL’s prepackaged binaries.
UPDATE: The troubleshooting page has been updated to include an alternative: using “sudo -s” to start a root shell. I still like my one-liner better :-)
UPDATE 2: Using env instead of bash is slightly cleaner.
UPDATE 3: MySQL still has some problems, because the library is pointing to the wrong direction. The quick solution is to create a link to the right place:
sudo ln -s /usr/local/bin/mysql/lib /usr/local/bin/mysql/lib/mysql
October 25th, 2007 at 5:16 pm
“sudo gem install mysql — -arch i386″ might also work.
October 25th, 2007 at 5:20 pm
Doggie, it doesn’t work, because ruby’s extconf still inserts it’s own flags, so you end up with -arch i386 –more-flags-here -arch ppc -arch i386
October 25th, 2007 at 5:54 pm
Alternatively, you can configure the sudoers file to pass ARCHFLAGS ($ sudo visudo).
October 27th, 2007 at 12:11 am
I can’t seem to get mysql itself to work… how did you install mysql on leopard?
October 28th, 2007 at 8:15 pm
[…] ruby mysql gem on Leo, saved. October 29th, 2007 http://trac.macosforge.org/projects/ruby/wiki/Troubleshooting http://www.notsostupid.com/blog/2007/10/25/ruby-leopard-and-gems/ […]
October 29th, 2007 at 12:00 am
I tried using mysql module on Leopard but it still fails. Here is the output. Any thoughts ?
localhost-3:early-prog $ uname -a
Darwin localhost-3.local 9.0.0 Darwin Kernel Version 9.0.0: Tue Oct 9 21:35:55 PDT 2007; root:xnu-1228~1/RELEASE_I386 i386
localhost-3:early-prog $ sudo bash -c “ARCHFLAGS=’-arch i386′ gem install mysql”
Select which gem to install for your platform (universal-darwin9.0)
1. mysql 2.7.3 (mswin32)
2. mysql 2.7.1 (mswin32)
3. mysql 2.7 (ruby)
4. mysql 2.6 (ruby)
5. Skip this gem
6. Cancel installation
> 3
Building native extensions. This could take a while…
ERROR: While executing gem … (Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.
ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lm… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lz… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lsocket… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lnsl… no
checking for mysql_query() in -lmysqlclient… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
–with-mysql-config
–without-mysql-config
–with-mysql-dir
–without-mysql-dir
–with-mysql-include
–without-mysql-include=${mysql-dir}/include
–with-mysql-lib
–without-mysql-lib=${mysql-dir}/lib
–with-mysqlclientlib
–without-mysqlclientlib
–with-mlib
–without-mlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-zlib
–without-zlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-socketlib
–without-socketlib
–with-mysqlclientlib
–without-mysqlclientlib
–with-nsllib
–without-nsllib
–with-mysqlclientlib
–without-mysqlclientlib
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.7/gem_make.out
localhost-3:early-prog $
October 29th, 2007 at 8:10 am
Liz…. Check out the information at http://trac.macosforge.org/projects/ruby/wiki/Troubleshooting
October 29th, 2007 at 9:11 am
So I see my post was moderated. Any thoughts on why am I seeing those errors ? I don’t think I have to have mysql installed on my system to have ruby load up mysql module ? DO I have to ?
October 30th, 2007 at 3:41 pm
regarding update 3: instead of making a link, why not tell it the right place? here is what i used (with macports install of mysql):
sudo env ARCHFLAGS=”-arch ppc” gem install mysql — –with-mysql-include=/opt/local/include/mysql5/mysql/ –with-mysql-lib=/opt/local/lib/mysql5/mysql/
note: if you copy this, change ‘ppc’ as needed
November 2nd, 2007 at 12:28 am
I am getting the same issue as Aashish. What to do?
November 2nd, 2007 at 12:37 am
Also, it is saying I don’t have permission to the /usr/bin directory. Should I change this, and if so how. Finally, it is telling me that extconf.rb cannot be found. I installed the XCode Tools. How do I get this file, and what happened to it?
November 2nd, 2007 at 12:49 am
This will be helpful to some folks:
Migrating MySQL 5.0.45 to Mac OS X 10 .5 Leopard http://blog.tomatocheese.com/archives/2007/11/1/migrating_mysql_to_mac_os_x_leopard/
November 3rd, 2007 at 1:27 pm
Aashish and Evan - I had the same problem, and this is what finally worked for me:
sudo bash -c “ARCHFLAGS=’-arch i386′ gem install mysql — -with-mysql-dir=/usr/local/mysql –with-mysql-lib=/usr/local/mysql/lib –with-mysql-include=/usr/local/mysql/include”
November 6th, 2007 at 10:35 am
Step By Step Reinstall, and startup command instructions for MySQL
http://www.developingchris.com/2007/10/26/mysql-and-os-x-105-leopard/
December 6th, 2007 at 12:47 am
For MacPorts install of MySQL, this worked for me (based on Ben and Elliot above):
sudo bash -c “ARCHFLAGS=’-arch i386′ gem install mysql — –with-mysql-dir=/opt/local/lib/mysql5 –with-mysql-lib=/opt/local/lib/mysql5/mysql –with-mysql-include=/opt/local/include/mysql5/mysql”
December 10th, 2007 at 11:44 pm
f you have a PPC Mac (I hear some still exist), you’d enter:
sudo env ARCHFLAGS=”-arch ppc” gem install mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config
December 29th, 2007 at 12:25 am
[…] Ruby, Leopard and gems A couple of notes about building native gems on leopard (tags: Leopard postgresql mysql ruby osx) Leave a Comment […]
January 18th, 2008 at 1:45 am
none of the above seemed to have worked for me, but this did:
http://www.schmidp.com/2007/9/29/rails-mysql-and-leopard