Rails安装eventmachine提示出错的解决方法

github中的项目其中需要eventmachine包:

gem 'eventmachine'

但是直接bundle出错,提示找不到openssl/ssl.h头文件:

make "DESTDIR="
compiling binder.cpp
In file included from binder.cpp:20:
./project.h:107:10: fatal error: 'openssl/ssl.h' file not found
#include <openssl/ssl.h>
         ^
1 error generated.
make: *** [binder.o] Error 1

首先确定系统中安装了openssl库,然后指定include路径编译:

gem install eventmachine -- --with-cppflags=-I/usr/local/opt/openssl/include
Fetching: eventmachine-1.2.3.gem (100%)
Building native extensions with: '--with-cppflags=-I/usr/local/opt/openssl/include'
This could take a while...
Successfully installed eventmachine-1.2.3
1 gem installed

但是再次bundle还是出错,rails安装的是1.0.3版本,但刚才装的是1.2.3版本,我们指定1.0.3版本再次试一下:

gem install eventmachine -v '1.0.3' -- --with-cppflags=-I/usr/local/opt/openssl/include

可惜还是出错:

ERROR:  Error installing eventmachine:
    ERROR: Failed to build gem native extension.

    /Users/apple/.rvm/rubies/ruby-2.2.5/bin/ruby -r ./siteconf20170228-3267-j31ccl.rb extconf.rb --with-cppflags=-I/usr/local/opt/openssl/include
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... no
checking for inotify_init() in sys/inotify.h... no
checking for __NR_inotify_init in sys/syscall.h... no
checking for writev() in sys/uio.h... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enable_interrupt()... no
checking for rb_time_new()... yes
checking for sys/event.h... yes
checking for sys/queue.h... yes
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling binder.cpp
compiling cmain.cpp
compiling ed.cpp
compiling em.cpp
em.cpp:827:9: error: use of undeclared identifier 'rb_thread_select'; did you mean 'rb_thread_fd_select'?
        return EmSelect (maxsocket+1, &fdreads, &fdwrites, &fderrors, &tv);
               ^~~~~~~~
               rb_thread_fd_select
./em.h:25:20: note: expanded from macro 'EmSelect'
  #define EmSelect rb_thread_select
                   ^
/Users/apple/.rvm/rubies/ruby-2.2.5/include/ruby-2.2.0/ruby/intern.h:454:5: note: 'rb_thread_fd_select' declared here
int rb_thread_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *);
    ^
em.cpp:827:32: error: cannot initialize a parameter of type 'rb_fdset_t *' with an rvalue of type 'fd_set *'
        return EmSelect (maxsocket+1, &fdreads, &fdwrites, &fderrors, &tv);
                                      ^~~~~~~~
/Users/apple/.rvm/rubies/ruby-2.2.5/include/ruby-2.2.0/ruby/intern.h:454:42: note: passing argument to parameter here
int rb_thread_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *);
                                         ^
em.cpp:946:6: error: use of undeclared identifier 'rb_thread_select'; did you mean 'rb_thread_fd_select'?
                                        EmSelect (0, NULL, NULL, NULL, &tv);
                                        ^~~~~~~~
                                        rb_thread_fd_select
./em.h:25:20: note: expanded from macro 'EmSelect'
  #define EmSelect rb_thread_select
                   ^
/Users/apple/.rvm/rubies/ruby-2.2.5/include/ruby-2.2.0/ruby/intern.h:454:5: note: 'rb_thread_fd_select' declared here
int rb_thread_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *);
    ^
3 errors generated.

貌似1.0.3源码不兼容啊,一种办法就是修改源代码,顺利的话也很好,但不顺利的话…. ;( ,所以我们还是下面直接用新版本试一下,在Gemfile中手动指定版本:

gem 'eventmachine','1.2.3'

运行bundle,出错!!!提示如下:

You have requested:
  eventmachine = 1.2.3

The bundle currently has eventmachine locked at 1.0.3.
Try running `bundle update eventmachine`

If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`

我们还得update一下:

bundle update eventmachine

最后安装成功,但是这样有一个问题:当rails项目指定gem版本时最好不要修改其版本,即使是更新!因为可能涉及到代码兼容性问题.这里是不得已而为之的办法,最终项目是否可以成功运行还得再观察 ;)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大熊猫侯佩

赏点钱让我买杯可乐好吗 ;)

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值