您的位置:首页 > 大数据 > 人工智能

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

2017-02-28 10:52 441 查看
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版本时最好不要修改其版本,即使是更新!因为可能涉及到代码兼容性问题.这里是不得已而为之的办法,最终项目是否可以成功运行还得再观察 ;)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐