본문 바로가기

기술/Ruby on Rails

RoR 사용시 Rake 에서 발생하는 Library not loaded libmysqlclient.18.dylib 오류 해결법


우선 나의 작업 환경은 다음과 같다.

Mac OS X  10.7.2
         Ruby   1.9.2p180
         Rails    3.1.3 
                      mysql2 gem 0.3.11
RubyMine   3.2.4 


얼마전부터 개발용 IDE를 Aptana Studio 3 에서 RubyMine으로 바꾸었는데, IDE 자체가 가볍고 기능도 더 직관적이라 매우 만족하며 사용하고 있었다. 그러던 중 문제가 하나 발생하였다.

RubyMine의 Rake 명령어 자동 완성 기능은 꽤나 유용해서 자주 사용하던 것이었는데, 프로젝트 생성시 데이타베이스를 mysql로 선택하면 오류가 발생하면서 rake 명령어 목록을 불러오지 못하는 것이었다.

/Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:236:in `require': dlopen(/Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/mysql2-0.3.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)

  Referenced from: /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/mysql2-0.3.6/lib/mysql2/mysql2.bundle

  Reason: image not found - /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/mysql2-0.3.6/lib/mysql2/mysql2.bundle

    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:236:in `block in require'

    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:222:in `block in load_dependency'

    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:616:in `new_constants_in'

    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:222:in `load_dependency'

    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:236:in `require'

    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/mysql2-0.3.6/lib/mysql2.rb:9:in `<top (required)>'

    from /Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in `require'

    from /Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in `block (2 levels) in require'

    from /Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.15/lib/bundler/runtime.rb:66:in `each'

    from /Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.15/lib/bundler/runtime.rb:66:in `block in require'

    from /Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.15/lib/bundler/runtime.rb:55:in `each'

    from /Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.15/lib/bundler/runtime.rb:55:in `require'

    from /Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.15/lib/bundler.rb:120:in `require'

    from /Users/ror/projects/restaurant/config/application.rb:7:in `<top (required)>'

    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/commands.rb:38:in `require'

    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/commands.rb:38:in `<top (required)>'

    from script/rails:6:in `require'

    from script/rails:6:in `<main>'

<에러메시지가 더이상 발생하지 않아서 웹에 있는 다른 사람의 로그를 가져왔다>

매우 복잡하지만 중요한 메시지는 libmysqlclient.18.dylib를 불러올 수 없다는 것이다. 라이브러리를 찾을 수 있도록 경로를 설정하여 주거나 라이브러리를 복사해 넣으면 이 것을 해결할 수 있다.

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib


위와 같은 명령어를 콘솔에 실행하고 나니까 문제가 해결되었다. rake 의 명령어 리스트를 오류없이 RubyMine이 읽어올 수 있게 되어서 다음에서 보는 것처럼 rake 명령어를 좀 더 손쉽게 사용할 수 있게 되었다.


명령어 자동 완성 기능이 되니까 너무 편하다!!!! ㅋㅋㅋㅋ

참고한 웹 사이트의 URL: http://rorguide.blogspot.com/2011/07/getting-error-library-not-loaded.html