Installing latest Hpricot on ruby 1.8.5 fails due missing macro RARRAYPTR:
[root@silver ~]# gem install hpricot Building native extensions. This could take a while... ERROR: Error installing hpricot: ERROR: Failed to build gem native extension. /usr/bin/ruby extconf.rb checking for main() in -lc... yes creating Makefile make gcc -I. -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I. -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wall -fno-strict-aliasing -fPIC -c hpricot_css.c hpricot_css.rl: In function ‘hpricot_css’: hpricot_css.rl:106: warning: implicit declaration of function ‘RSTRING_PTR’ hpricot_css.rl:106: warning: assignment makes pointer from integer without a cast hpricot_css.rl:107: warning: implicit declaration of function ‘RSTRING_LEN’ hpricot_css.rl:82: warning: field precision should have type ‘int’, but argument 5 has type ‘long int’ hpricot_css.c:295: warning: comparison is always true due to limited range of data type [...] hpricot_css.c:3403: warning: comparison between pointer and integer hpricot_css.c:3403: warning: ‘eof’ is used uninitialized in this function hpricot_css.rl:92: warning: ‘aps’ may be used uninitialized in this function gcc -I. -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I. -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wall -fno-strict-aliasing -fPIC -c hpricot_scan.c hpricot_scan.rl: In function ‘our_rb_hash_lookup’: hpricot_scan.rl:169: warning: implicit declaration of function ‘st_lookup’ hpricot_scan.rl: In function ‘make_hpricot_struct’: hpricot_scan.rl:693: warning: implicit declaration of function ‘RARRAYPTR’ hpricot_scan.rl:693: error: subscripted value is neither array nor pointer make: *** [hpricot_scan.o] Error 1 Gem files will remain installed in /usr/lib64/ruby/gems/1.8/gems/hpricot-0.8.1 for inspection. Results logged to /usr/lib64/ruby/gems/1.8/gems/hpricot-0.8.1/ext/hpricot_scan/gem_make.out
Searching with google I’ve found this post that explains equivalence of the RARRAYPTR(v) is RARRAY(v)->ptr . We’ll need to define RARRAYPTR macro.
We’ll replace occurences of #include <ruby.h> with #include “ruby_macros.h” and create an include file ruby_macros.h with the following content:
#ifndef __RUBY_MACROS__ #define __RUBY_MACROS__ #include <ruby.h> #ifndef RARRAYPTR # define RARRAYPTR(v) RARRAY(v)->ptr #endif #endif
[root@silver ~]# cd /usr/lib64/ruby/gems/1.8/gems/hpricot-0.8.1/ext/hpricot_scan [root@silver hpricot_scan]# sed -i 's,#include <ruby.h>,#include "ruby_macros.h",g' *.h *.c *.rl [root@silver hpricot_scan]# touch ruby_macros.h [root@silver hpricot_scan]# vi ruby_macros.h
The next step is to recreate the gem and install it:
[root@silver ~]# cd /usr/lib64/ruby/gems/1.8/gems/hpricot-0.8.1 [root@silver hpricot-0.8.1]# rake package (in /usr/lib64/ruby/gems/1.8/gems/hpricot-0.8.1) fatal: Not a git repository rm -r ext/fast_xs/Makefile rm -r ext/hpricot_scan/Makefile rm -r .config rm -r pkg rm -r hpricot-0.8.1-mswin32 rm -r hpricot-0.8.1-jruby Using ragel version: 6.3, location: /usr/bin/ragel cd ext/hpricot_scan ; ragel hpricot_scan.rl -G2 -o hpricot_scan.c && ragel hpricot_css.rl -G2 -o hpricot_css.c mkdir -p pkg mkdir -p pkg/hpricot-0.8.1 rm -f pkg/hpricot-0.8.1/CHANGELOG [...] cd pkg tar zcvf hpricot-0.8.1.tgz hpricot-0.8.1 hpricot-0.8.1/ hpricot-0.8.1/Rakefile [...] hpricot-0.8.1/ext/fast_xs/fast_xs.c cd - WARNING: description and summary are identical Successfully built RubyGem Name: hpricot Version: 0.8.1 File: hpricot-0.8.1.gem mv hpricot-0.8.1.gem pkg/hpricot-0.8.1.gem
[root@silver hpricot-0.8.1]# gem install pkg/hpricot-0.8.1.gem Building native extensions. This could take a while... Successfully installed hpricot-0.8.1 1 gem installed Installing ri documentation for hpricot-0.8.1... Installing RDoc documentation for hpricot-0.8.1... [root@silver hpricot_scan]# gem list -l | grep hpricot hpricot (0.8.1, 0.7, 0.6.164, 0.6.161, 0.6)
17 comments ↓
I am encountering this same problem w/ the hpricot (0.8.1) library in my environment (Ruby 1.8.5). Attempted your solution. All was going well until I tried to make & install the new package (final step). Then I received the following:
[root@XXXXXXXX hpricot-0.8.1]# gem install pkg/hpricot-0.8.1.gem
Building native extensions. This could take a while…
ERROR: Error installing pkg/hpricot-0.8.1.gem:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
checking for main() in -lc… yes
creating Makefile
make
gcc -I. -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I. -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector –param=ssp-buffer-size=4 -m64 -mtune=generic -Wall -fPIC -c hpricot_css.c
hpricot_css.rl:89: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘hpricot_css’
make: *** [hpricot_css.o] Error 1
Gem files will remain installed in /usr/lib64/ruby/gems/1.8/gems/hpricot-0.8.1 for inspection.
Results logged to /usr/lib64/ruby/gems/1.8/gems/hpricot-0.8.1/ext/hpricot_scan/gem_make.out
Dou you have ragel installed ?
[root@silver hpricot-0.8.1]# ragel –version
Ragel State Machine Compiler version 6.3 August 2008
Copyright (c) 2001-2007 by Adrian Thurston
Try to run ‘make clean && make’ in ‘ext/hpricot_scan’ and then repeat the last step.
This solution worked for me as well.
Only difference is that I had to use RARRAY_PTR instead of RARRAYPTR.
Some system info:
CentOS 5
Ragel v6.5
Ruby 1.8.5
RubyGems 1.3.1
I had the same issue as Dan P. This is the output after doing the make clean && make in the scan directory.
Any ideas? (ruby 1.8.5 / centos 5.3)
-bash-3.2# gem install pkg/hpricot-0.8.1.gem
Building native extensions. This could take a while…
ERROR: Error installing pkg/hpricot-0.8.1.gem:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb install pkg/hpricot-0.8.1.gem
checking for main() in -lc… yes
creating Makefile
make
gcc -I. -I. -I/usr/lib/ruby/1.8/i386-linux -I. -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector –param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -fno-strict-aliasing -fPIC -c hpricot_scan.c
hpricot_scan.rl: In function ‘our_rb_hash_lookup’:
hpricot_scan.rl:169: warning: implicit declaration of function ‘st_lookup’
hpricot_scan.rl: In function ‘make_hpricot_struct’:
hpricot_scan.rl:693: warning: implicit declaration of function ‘RARRAY_PTR’
hpricot_scan.rl:693: error: subscripted value is neither array nor pointer
make: *** [hpricot_scan.o] Error 1
Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/hpricot-0.8.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/hpricot-0.8.1/ext/hpricot_scan/gem_make.out
gem install ragel
ERROR: could not find gem ragel locally or in a repository
???
You need to install ragel, if you are using linux you can find RPM package for your distribution on http://rpm.pbone.net .
[...] 直接gemファイルを指定してインストールを試みるものの、なぜかうまく行かない。 上記のblogで紹介されていたHpricot 0.8.1 on ruby 1.8.5 | Penguin on Railsを参考に下記の通り実行することでインストールできた。 [...]
Same comment (and same configuration) as Jed about RARRAY_PTR instead of RARRAYPTR.
Just change ruby_macros.h to:
#ifndef __RUBY_MACROS__
#define __RUBY_MACROS__
#include
#ifndef RARRAY_PTR
# define RARRAY_PTR(v) RARRAY(v)->ptr
#endif
#endif
Thanks for this! I was able to fix a very similar problem. In my case I was getting:
hpricot_scan.rl:181: warning: implicit declaration of function ‘RSTRUCT_PTR’
…followed by a flood of “subscripted value is neither array nor pointer” errors. So in my ruby_macros.h file, I put:
#ifndef RSTRUCT_PTR
# define RSTRUCT_PTR(v) RSTRUCT(v)->ptr
#endif
And it worked!
(I also had to install Ragel 6.5 from source as apt-get in Ubuntu Dapper would only install 5.1. This is w/ Ruby 1.8.4, RubyGems 1.3.5, and Hpricot 0.8.1.)
Actually, scratch that; it _installed_ successfully, but once I tried to execute Hpricot code in irb, it bailed with an “undefined symbol: RSTRING_PTR” error.
So, I started my Ruby install from scratch, building 1.8.6 from source rather than sticking with the 1.8.4 apt-get offered… A few headaches later, everything works!
sudo apt-get install ruby1.8-dev
worked for me.
http://github.com/defunkt/hpricot
that worked on 1.8.5
[...] la solución en un blog, el problema era que la versión de Ruby bajo la que operan los grid containers es la 1.8.5 y para [...]
Hi,
for me it worked after manual installation of ragel (source code) and changing the ruby_macros.h to
#ifndef __RUBY_MACROS__
#define __RUBY_MACROS__
#include
#ifndef RARRAYPTR
# define RARRAYPTR(v) RARRAY(v)->ptr
#endif
#ifndef RARRAY_PTR
# define RARRAY_PTR(v) RARRAY(v)->ptr
#endif
#ifndef RSTRUCT_PTR
# define RSTRUCT_PTR(v) RSTRUCT(v)->ptr
#endif
#endif
After this I did the sed from above and performed a
ruby setup.rg in the gem-root. Did this again and then 2 times a “rake install” in the gem-root.
Strangely it did not work the 1st time therefore I repeated both “installs”
Thanks for your efforts!
CentOS release 4.3 (Final), ruby 1.8.7 (Source)
Correction to the comment above:
1) gem install hpricot
2) cd $GEM_SOURCE (see from error message above)
3) cd ext/hpricot_scan
4) sed -i ’s,#include ,#include “ruby_macros.h”,g’ *.h *.c *.rl
5) vi ruby_macros.h
#ifndef __RUBY_MACROS__
#define __RUBY_MACROS__
#include <ruby.h>
#ifndef RARRAYPTR
# define RARRAYPTR(v) RARRAY(v)->ptr
#endif
#ifndef RARRAY_PTR
# define RARRAY_PTR(v) RARRAY(v)->ptr
#endif
#ifndef RSTRUCT_PTR
# define RSTRUCT_PTR(v) RSTRUCT(v)->ptr
#endif
#endif
rake install (still 2 times necessary)
(include “lower-than”ruby.h”greater-than”… dunno if the braces/brackets whatever appear in the comment)
6) cd $GEM_SOURCE (see above)
7) rake install
that’s it.
I’ve switched to Nokogiri, it’s more robust and easier to install:
http://nokogiri.org/
http://github.com/tenderlove/nokogiri
http://tenderlovemaking.com/category/computadora/nokogiri/
gem install hpricot -v 0.7
no problem on centos 5
Leave a Comment