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}`

No comments: