gem install mongrel fails with ruby 1.9.1

2019-03-14 11:06发布

问题:

I initiated myself into rails development yesterday.
I installed ruby 1.9.1, rubygems and rails.
Running gem install mongrel worked fine and ostensibly installed mongrel too. I am slightly puzzled because:

  • script/server starts webrick by default
  • which mongrel returns nothing
  • locate mongrel returns lots of entries like
/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1
/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib
/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel
.
.
.
/usr/local/bin/mongrel_rails
/usr/local/lib/ruby/gems/1.9.1/cache/mongrel-1.1.5.gem
/usr/local/lib/ruby/gems/1.9.1/doc/actionpack-2.3.2/rdoc/files/lib/action_controller/vendor/rack-1_0/rack/handler/evented_mongrel_rb.html
/usr/local/lib/ruby/gems/1.9.1/doc/actionpack-2.3.2/rdoc/files/lib/action_controller/vendor/rack-1_0/rack/handler/mongrel_rb.html
/usr/local/lib/ruby/gems/1.9.1/doc/actionpack-2.3.2/rdoc/files/lib/action_controller/vendor/rack-1_0/rack/handler/swiftiplied_mongrel_rb.html
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/handler/evented_mongrel.rb
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/handler/swiftiplied_mongrel.rb
/usr/local/lib/ruby/gems/1.9.1/gems/mongrel-1.1.5
.
.
.

Does look like I have mongrel installed (both the default installation and my custom install). So why doesn't which mongrel return something.

Also trying to reinstall mongrel using gem install mongrel returns throws its own set of exceptions:

Building native extensions.  This could take a while...
ERROR:  Error installing mongrel:
    ERROR: Failed to build gem native extension.

/usr/local/bin/ruby extconf.rb install mongrel
checking for main() in -lc... yes
creating Makefile

make
gcc -I. -I/usr/local/include/ruby-1.9.1/i386-darwin9.7.0 -I/usr/local/include/ruby-1.9.1/ruby/backward -I/usr/local/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -fno-common -D_XOPEN_SOURCE=1 -O2 -g -Wall -Wno-parentheses  -fno-common -pipe -fno-common  -o http11.o -c http11.c
http11.c: In function 'http_field':
http11.c:77: error: 'struct RString' has no member named 'ptr'
http11.c:77: error: 'struct RString' has no member named 'len'
http11.c:77: warning: left-hand operand of comma expression has no effect
http11.c:77: warning: statement with no effect
http11.c: In function 'header_done':
http11.c:172: error: 'struct RString' has no member named 'ptr'
http11.c:174: error: 'struct RString' has no member named 'ptr'
http11.c:176: error: 'struct RString' has no member named 'ptr'
http11.c:177: error: 'struct RString' has no member named 'len'
http11.c: In function 'HttpParser_execute':
http11.c:298: error: 'struct RString' has no member named 'ptr'
http11.c:299: error: 'struct RString' has no member named 'len'
make: *** [http11.o] Error 1

回答1:

It looks like other people are having problems running Mongrel on Ruby 1.9.

The comment by Ami Mahloof seems like it might be a possible fix:

Here’s What you need to do in order to fix it

here’s the updated instructions:

1) cd /usr/local/lib/ruby/gems/1.9.1/gems/mongrel-1.1.5/ext/http11

2) sudo vi / mate on http11.c and:

replace line 77 with

for(ch = RSTRING_PTR(f), end = ch + RSTRING_LEN(f); ch < end; ch++) {

replace line 172 with

colon = strchr(RSTRING_PTR(temp), ':');

replace line 174 with

rb_hash_aset(req, global_server_name, rb_str_substr(temp, 0, colon - RSTRING_PTR(temp)));

replce line 176,177

rb_str_substr(temp, colon - RSTRING_PTR(temp)+1, RSTRING_LEN(temp)));

replace lines 298 299

dptr = RSTRING_PTR(data);

dlen = RSTRING_LEN(data);

3) save the file, close the vi / textmate

4) sudo ruby extconf.rb && sudo make && sudo make install

5) cd ../../lib/mongrel (or the full path “/usr/local/lib/ruby/gems/1.9.1/gems/mongrel-1.1.5/lib/mongrel”

6) mate / sudo vi handlers.rb

7) fix the case statements in

On lines 208-212, change instances of “: false” to “then false”

8) sudo gem install gem_plugin (else mongrel may hang)

done!



回答2:

You can install mongrel 1.2 prerelease with sudo gem install mongrel --pre:

$ sudo gem1.9 install mongrel --pre
> Building native extensions.  This could take a while...
> Successfully installed mongrel-1.2.0.pre2
> 1 gem installed


回答3:

It is a compilation issue so it’s easier to do this:

git clone git://github.com/mongrel/mongrel.git

cd mongrel/ext/http/

Now edit the http11.c:

#ifndef RSTRING_PTR
#define RSTRING_PTR(s) (RSTRING(s))
#endif
#ifndef RSTRING_LEN
#define RSTRING_LEN(s) (RSTRING(s))
#endif

Save it and now from the same directory do the following:

sudo ruby extconf.rb && sudo make && sudo make install

Done!



回答4:

You Can Force To Install mongrel like this

sudo gem install mongrel -v 1.2.0.pre2 -- --with-cflags=\"-O2 -pipe -march=native -w\"

This Solve the issue.