为 eventmachine -v '0.12.10' 安装本机 gem 时编译错误

Compile error when installing native gem for eventmachine -v '0.12.10'

我在使用 rake bundle_install 设置项目时遇到问题:

$ rake bundle_install
cd nats && bundle install
rake aborted!
Command failed with status (5): [cd nats && bundle install...]

Tasks: TOP => bundle_install
(See full trace by running task with --trace)
Fetching gem metadata from http://rubygems.org/.........
Resolving dependencies...
Using rake (0.9.2.2) 
Using daemons (1.1.8) 
Using diff-lcs (1.1.3) 
Installing eventmachine (0.12.10) 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb 
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... yes
checking for inotify_init() in sys/inotify.h... yes
checking for writev() in sys/uio.h... yes
checking for rb_thread_check_ints()... yes
checking for rb_time_new()... yes
checking for sys/event.h... no
checking for epoll_create() in sys/epoll.h... yes
checking for main() in -lcrypto... no
creating Makefile

make
compiling sigs.cpp
compiling cplusplus.cpp
compiling files.cpp
compiling kb.cpp
kb.cpp: In member function ‘virtual void KeyboardDescriptor::Read()’:
kb.cpp:79:27: warning: ignoring return value of ‘ssize_t read(int, void*, size_t)’, declared with attribute warn_unused_result [-Wunused-result]
  read (GetSocket(), &c, 1);
                       ^
compiling rubymain.cpp
rubymain.cpp: In function ‘VALUE t_connect_server(VALUE, VALUE, VALUE)’:
rubymain.cpp:468:42: error: format not a string literal and no format arguments [-Werror=format-security]
   rb_raise (EM_eConnectionError, e.what());
                                          ^
rubymain.cpp: In function ‘VALUE t_bind_connect_server(VALUE, VALUE, VALUE, VALUE, VALUE)’:
rubymain.cpp:488:42: error: format not a string literal and no format arguments [-Werror=format-security]
   rb_raise (EM_eConnectionError, e.what());
                                          ^
cc1plus: some warnings being treated as errors
make: *** [rubymain.o] Error 1


Gem files will remain installed in /home/heavenize/.bundler/tmp/15236/gems/eventmachine-0.12.10 for inspection.
Results logged to /home/heavenize/.bundler/tmp/15236/gems/eventmachine-0.12.10/ext/gem_make.out
An error occurred while installing eventmachine (0.12.10), and Bundler cannot continue.
Make sure that `gem install eventmachine -v '0.12.10'` succeeds before bundling.

然后当我尝试 eventmachine 的所需版本时,我得到了以下输出:

$  sudo gem install eventmachine -v '0.12.10'
ERROR:  Error installing eventmachine:
ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... yes
checking for inotify_init() in sys/inotify.h... yes
checking for writev() in sys/uio.h... yes
checking for rb_thread_check_ints()... yes
checking for rb_time_new()... yes
checking for sys/event.h... no
checking for epoll_create() in sys/epoll.h... yes
checking for main() in -lcrypto... no
creating Makefile

make
compiling sigs.cpp
compiling cplusplus.cpp
compiling files.cpp
compiling kb.cpp
kb.cpp: In member function ‘virtual void KeyboardDescriptor::Read()’:
kb.cpp:79:27: warning: ignoring return value of ‘ssize_t read(int, void*, size_t)’, declared with attribute warn_unused_result [-Wunused-result]
  read (GetSocket(), &c, 1);
                           ^
compiling rubymain.cpp
rubymain.cpp: In function ‘VALUE t_connect_server(VALUE, VALUE, VALUE)’:
rubymain.cpp:468:42: error: format not a string literal and no format arguments [-Werror=format-security]
   rb_raise (EM_eConnectionError, e.what());
                                          ^
rubymain.cpp: In function ‘VALUE t_bind_connect_server(VALUE, VALUE, VALUE, VALUE, VALUE)’:
rubymain.cpp:488:42: error: format not a string literal and no format arguments [-Werror=format-security]
   rb_raise (EM_eConnectionError, e.what());
                                          ^
cc1plus: some warnings being treated as errors
make: *** [rubymain.o] Error 1


Gem files will remain installed in /var/lib/gems/1.9.1/gems/eventmachine-0.12.10 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/eventmachine-0.12.10/ext/gem_make.out

我有以下设置:

$ rake --version
rake, version 0.9.2.2
$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]

如何解决这个问题?

据我所知,这个版本似乎有问题,我发现解决这个问题的唯一方法是 thread。我的建议是查看 Gemfile.lock 并查看哪个 gem 需要该版本,然后考虑您是否真的需要它或检查 gem 是否已更新,因为那是一个非常旧的 eventmachine 版本.