Wednesday, May 16, 2012

Much better way to fix "home_dir/.rvm/gems/ruby-1.9.2-p290@gemset/gems/mysql2-0.2.18/lib/mysql2.rb:9:in `require': dlopen(home_dir/.rvm/gems/ruby-1.9.2-p290@gemset/gems/mysql2-0.2.18/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)"

I found this on this blog

 Simply add: export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/ to your .bash_profile, .bashrc file in your home directory (or whatever file is consulted when an interactive login shell is started) and source the file:

 . ~/.bashrc

Monday, January 16, 2012

How to fix -- dlopen(/Users/user/.rvm/gems/ruby-1.9.2-p290@gemset/gems/do_mysql-0.10.7/lib/do_mysql/do_mysql.bundle, 9): Library not loaded

Recently when working with a new gemset in RVM, I noticed that the gem install of mysql-0.10.7, the C extensions be exact, did not link correctly against the mysqllibclient dynamic library. I don't really know why this at this point. I needed to get it fixed. Stackoverflow to the rescue, but I wanted to post the script I made to make this easier.

The error when running my Sinatra app:

dlopen(/Users/users/.rvm/gems/ruby-1.9.2-p290@gemset/gems/do_mysql-0.10.7/lib/do_mysql/do_mysql.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)

The ruby script for the fix:

#!/bin/env ruby
mysql_bundle = `find ~ -name do_mysql.bundle`
mysql_lib = 'libmysqlclient.18.dylib'
mysql_lib_location = `find /usr/local -name #{mysql_lib}`
m_array = mysql_lib_location.split
mysql_lib_path = m_array.first if m_array
mysql_bundle.split.each do |bundle|
`/usr/bin/install_name_tool -change #{mysql_lib} #{mysql_lib_path} #{bundle}`