Rails - cannot run app: Unable to load the EventMachine C extension;
Asked Answered
E

6

5

When I run an app on Lion OS X, I get this error:

Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby'
/Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-1.0.0/lib/eventmachine.rb:8:in `require': no such file to load -- rubyeventmachine (LoadError)
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-1.0.0/lib/eventmachine.rb:8:in `<top (required)>'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `block in require'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
    from /Users/adam/rubydev/future_computers/config/application.rb:7:in `<top (required)>'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands.rb:53:in `require'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands.rb:53:in `block in <top (required)>'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands.rb:50:in `tap'
    from /Users/adam/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'adam

I don't really know how to fix this, I've added the eventmachine gem into the Gemfile, but it didn't help...

Could you help me, please, how to fix it?

Thank you

Eisenhart answered 12/2, 2013 at 1:53 Comment(2)
Did you got any errors with bundle install?Sorption
bundle install works without any errors.Eisenhart
Z
19

In my case this fixed it:

  • $ gem uninstall eventmachine
  • at the prompt tell it to uninstall all versions (it tells you about dependencies)
  • $ bundle install

I was reading through this https://github.com/eventmachine/eventmachine/issues/333. There were problems with eventmachine, so making sure I got the newest version seemed a good idea.

Zackzackariah answered 28/2, 2013 at 16:28 Comment(1)
This didn't work for me - I still get the exact same error.Desai
T
9

For me, compiling eventmachine from sources with tweaked config helped. Try:

Uninstall eventmachine if it's already installed:

gem uninstall eventmachine

Fetch eventmachine sources:

git clone https://github.com/eventmachine/eventmachine.git
cd eventmachine

Edit ext/extconf.rb and ext/fastfilereader/extconf.rb files by adding CONFIG['CXX'] = "g++" right after require 'mkmf'

Compile and install gem:

rake gem
gem install pkg/eventmachine-1.0.3.gem

Now eventmachine should work just fine :)

Tungsten answered 6/1, 2014 at 12:27 Comment(3)
this worked for mailcatcher to start but somehow broke my bundle install.. figuring that atmSolfa
Checked out v1.0.3 and performed the edits. Now I am getting a Don't know how to build task 'native:eventmachine:x86-mingw32' (see --tasks)Antevert
Elijah are you running Windows? The changes worked for me on macOS. This might help you: github.com/eventmachine/eventmachine/issues/531Tungsten
S
2

The easiest fix as the message says is just to require 'em/pure_ruby'. I think you can put this in the config/inlitializers folder, you can call the file event_machine.rb

But it won't have the same performance as the C extension.

Sorption answered 12/2, 2013 at 2:42 Comment(2)
But where to find & download that file?Eisenhart
create it inside config/initializers folderSorption
M
1

I had that error when I run bundle exec jekyll serve --livereload --trace on Jekyll.4.2.1-Ruby.3.0.3p137(mingw)-Windows. I ran gem install eventmachine --platform=ruby and it compiled at C:\Ruby30-x64\lib\ruby\gems\3.0.0\gems\eventmachine-1.2.7 but when you run bundle install it creates also C:\Ruby30-x64\lib\ruby\gems\3.0.0\gems\eventmachine-1.2.7-x64-mingw32 🤔. The command bundle info eventmachine gives me C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/eventmachine-1.2.7-x64-mingw32 and that's confimed in the Gemfile.lock with the line eventmachine (1.2.7-x64-mingw32). So I changed that line for eventmachine (1.2.7) and then the output of bundle info eventmachine gives me C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/eventmachine-1.2.7 and finally the command bundle exec jekyll serve --livereload --trace worked ✔️

Microfilm answered 30/1, 2022 at 19:8 Comment(1)
Thanks, these steps work for me as well.Tardiff
H
0

Providing another solution as I just wasted hours tracking this issue down. I was doing bundle install --deployment and then committing the result to a separate branch in git so I could deploy this branch straight to servers without having to do bundle install again.

The problem is that eventmachine has a .gitignore file in it which tells git to ignore all *.so files. Because of this when I was committing, the .so files didn't commit, and wouldn't show up as untracked in a git status. Also since the gemspec was present, bundle thought the package was completely installed.

My solution was to add a command as part of the build process to go and whack all the .gitignore files in the gems before committing.

Hindquarter answered 22/4, 2013 at 1:40 Comment(2)
using git to store a lot of binary files might be headed for painScum
@BlakeMiller Yeah, we ended up abandoning this method and are building tarballs now.Hindquarter
T
0

You may find various errors while installing gems or trying to find solution to your ruby application installation failing due to ruby-devel was not installed.

I just installed on my Kali linux with

sudo apt-get install ruby-dev

and everything resolved. I was trying to install bettercap.

This answer helped: https://mcmap.net/q/75052/-gem-install-failed-to-build-gem-native-extension-can-39-t-find-header-files

Timorous answered 22/8, 2016 at 21:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.