結論
$ gem install cairo -- --with-opt-include=/usr/include/cairo
とコマンドを打つ。
-x86-mingw32のrcairoをインストールしているなら、アンインストールする。
rubyでcairoを使うための拡張ライブラリrcairoを、なんとかインストールすることができました。
自分の失敗例だとかを書くのは初めてなので、あまり上手く書けないかもしれない。
そもそも、エラー文を全然メモっていなかったので役に立たないかもしれない。
環境は
windows 7
cygwin
ruby 1.8.7
gem 1.8.10
です。
流れとしては
1.cairoインストール
2.rcairoインストール
1.cairoインストール
公式サイトによると、どうやらGTK+をインストールするだけでcairoもインストールされるらしい。
が、それにすら気づかないぼくは、こちらのブログを参考にしてインストールした。
cygwinのパッケージをちゃんとインストールしていないので、pixman以外にもいろいろ足りないといわれた(libpngなど)
そのたびに、cygwinのsetup.exeを実行してパッケージを入れた。それでも./configureで同じエラーが出たら、素直にtar.gzをダウンロードして展開、
$ ./configure
$ make
$ make install
でインストールしていった。
2.rcairoのインストール
ここに
For Windows user:
% gem install cairo –platform x86-mingw32
とあるので、その通りに実行
特にエラーもなく終了したが、requireできない。(cairo.soがないといわれる)
そもそもcygwinなのだから-mingw32はおかしい気がした。
なので
% gem install cairo
と普通に実行。
以下のエラーが出る。
$ gem install cairo
Fetching: cairo-1.10.1.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing cairo:
ERROR: Failed to build gem native extension.
/usr/bin/ruby.exe extconf.rb
checking for GCC... yes
checking for Win32 OS... yes
checking for Mac OS X... no
checking for cairo version (>= 1.2.0)... yes
checking for HAVE_RUBY_ST_H in ruby.h... no
checking for ruby/st.h... no
checking for HAVE_RUBY_IO_H in ruby.h... no
checking for ruby/io.h... no
checking for rb_errinfo() in ruby.h... no
checking for enum ruby_value_type in ruby.h... no
creating Makefile
make
gcc -I. -I. -I/usr/lib/ruby/1.8/i386-cygwin -I. -DRUBY_CAIRO_PLATFORM_WIN32 -DRB
_CAIRO_COMPILATION -g -O2 -Wall -I../../vendor/local/include -I../../vendor
/local/include/cairo -I../../vendor/local/include/pixman-1 -I../../vendor/local/
include/libpng15 -c rb_cairo.c
In file included from rb_cairo.c:17:
rb_cairo.h:20:19: cairo.h: No such file or directory
In file included from rb_cairo.c:17:
rb_cairo.h:209: error: parse error before '*' token
rb_cairo.h:209: 警告: type defaults to `int' in declaration of `rb_cairo_context
_from_ruby_object'
rb_cairo.h:209: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:210: error: parse error before '*' token
rb_cairo.h:212: error: parse error before '*' token
rb_cairo.h:212: 警告: type defaults to `int' in declaration of `rb_cairo_path_fr
om_ruby_object'
rb_cairo.h:212: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:213: error: parse error before '*' token
rb_cairo.h:215: error: parse error before '*' token
rb_cairo.h:215: 警告: type defaults to `int' in declaration of `rb_cairo_matrix_
from_ruby_object'
rb_cairo.h:215: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:216: error: parse error before '*' token
rb_cairo.h:223: error: parse error before '*' token
rb_cairo.h:223: 警告: type defaults to `int' in declaration of `rb_cairo_pattern
_from_ruby_object'
rb_cairo.h:223: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:224: error: parse error before '*' token
rb_cairo.h:226: error: parse error before '*' token
rb_cairo.h:226: 警告: type defaults to `int' in declaration of `rb_cairo_font_fa
ce_from_ruby_object'
rb_cairo.h:226: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:227: error: parse error before '*' token
rb_cairo.h:229: error: parse error before '*' token
rb_cairo.h:229: 警告: type defaults to `int' in declaration of `rb_cairo_font_ex
tents_from_ruby_object'
rb_cairo.h:229: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:230: error: parse error before '*' token
rb_cairo.h:232: error: parse error before '*' token
rb_cairo.h:232: 警告: type defaults to `int' in declaration of `rb_cairo_font_op
tions_from_ruby_object'
rb_cairo.h:232: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:233: error: parse error before '*' token
rb_cairo.h:235: error: parse error before '*' token
rb_cairo.h:235: 警告: type defaults to `int' in declaration of `rb_cairo_scaled_
font_from_ruby_object'
rb_cairo.h:235: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:236: error: parse error before '*' token
rb_cairo.h:238: error: parse error before '*' token
rb_cairo.h:238: 警告: type defaults to `int' in declaration of `rb_cairo_text_ex
tents_from_ruby_object'
rb_cairo.h:238: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:239: error: parse error before '*' token
rb_cairo.h:241: error: parse error before '*' token
rb_cairo.h:241: 警告: type defaults to `int' in declaration of `rb_cairo_glyph_f
rom_ruby_object'
rb_cairo.h:241: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:242: error: parse error before '*' token
rb_cairo.h:249: error: parse error before '*' token
rb_cairo.h:249: 警告: type defaults to `int' in declaration of `rb_cairo_surface
_from_ruby_object'
rb_cairo.h:249: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:250: error: parse error before '*' token
rb_cairo.h:252: error: parse error before '*' token
rb_cairo.h:297: error: parse error before "rb_cairo_operator_from_ruby_object"
rb_cairo.h:297: 警告: type defaults to `int' in declaration of `rb_cairo_operato
r_from_ruby_object'
rb_cairo.h:297: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:298: error: parse error before "rb_cairo_antialias_from_ruby_object"
rb_cairo.h:298: 警告: type defaults to `int' in declaration of `rb_cairo_antiali
as_from_ruby_object'
rb_cairo.h:298: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:299: error: parse error before "rb_cairo_fill_rule_from_ruby_object"
rb_cairo.h:299: 警告: type defaults to `int' in declaration of `rb_cairo_fill_ru
le_from_ruby_object'
rb_cairo.h:299: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:300: error: parse error before "rb_cairo_line_cap_from_ruby_object"
rb_cairo.h:300: 警告: type defaults to `int' in declaration of `rb_cairo_line_ca
p_from_ruby_object'
rb_cairo.h:300: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:301: error: parse error before "rb_cairo_line_join_from_ruby_object"
rb_cairo.h:301: 警告: type defaults to `int' in declaration of `rb_cairo_line_jo
in_from_ruby_object'
rb_cairo.h:301: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:302: error: parse error before "rb_cairo_font_slant_from_ruby_object"
rb_cairo.h:302: 警告: type defaults to `int' in declaration of `rb_cairo_font_sl
ant_from_ruby_object'
rb_cairo.h:302: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:303: error: parse error before "rb_cairo_font_weight_from_ruby_object
"
rb_cairo.h:303: 警告: type defaults to `int' in declaration of `rb_cairo_font_we
ight_from_ruby_object'
rb_cairo.h:303: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:304: error: parse error before "rb_cairo_subpixel_order_from_ruby_obj
ect"
rb_cairo.h:304: 警告: type defaults to `int' in declaration of `rb_cairo_subpixe
l_order_from_ruby_object'
rb_cairo.h:304: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:305: error: parse error before "rb_cairo_hint_style_from_ruby_object"
rb_cairo.h:305: 警告: type defaults to `int' in declaration of `rb_cairo_hint_st
yle_from_ruby_object'
rb_cairo.h:305: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:306: error: parse error before "rb_cairo_hint_metrics_from_ruby_objec
t"
rb_cairo.h:306: 警告: type defaults to `int' in declaration of `rb_cairo_hint_me
trics_from_ruby_object'
rb_cairo.h:306: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:307: error: parse error before "rb_cairo_path_data_type_from_ruby_obj
ect"
rb_cairo.h:307: 警告: type defaults to `int' in declaration of `rb_cairo_path_da
ta_type_from_ruby_object'
rb_cairo.h:307: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:308: error: parse error before "rb_cairo_content_from_ruby_object"
rb_cairo.h:308: 警告: type defaults to `int' in declaration of `rb_cairo_content
_from_ruby_object'
rb_cairo.h:308: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:309: error: parse error before "rb_cairo_format_from_ruby_object"
rb_cairo.h:309: 警告: type defaults to `int' in declaration of `rb_cairo_format_
from_ruby_object'
rb_cairo.h:309: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:310: error: parse error before "rb_cairo_extend_from_ruby_object"
rb_cairo.h:310: 警告: type defaults to `int' in declaration of `rb_cairo_extend_
from_ruby_object'
rb_cairo.h:310: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:311: error: parse error before "rb_cairo_filter_from_ruby_object"
rb_cairo.h:311: 警告: type defaults to `int' in declaration of `rb_cairo_filter_
from_ruby_object'
rb_cairo.h:311: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.h:335: error: parse error before "status"
In file included from rb_cairo.c:18:
rb_cairo_private.h:81: error: parse error before "cairo_glyph_t"
rb_cairo_private.h:84: error: parse error before "rb_cairo__is_kind_of"
rb_cairo_private.h:84: 警告: type defaults to `int' in declaration of `rb_cairo_
_is_kind_of'
rb_cairo_private.h:84: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo_private.h:112: error: parse error before "rb_cairo__exception_to_status
"
rb_cairo_private.h:112: 警告: type defaults to `int' in declaration of `rb_cairo
__exception_to_status'
rb_cairo_private.h:112: 警告: データ定義が型や記憶クラスを持っていません
rb_cairo.c: In function `rb_cairo_satisfied_version':
rb_cairo.c:40: error: `CAIRO_VERSION_MAJOR' undeclared (first use in this functi
on)
rb_cairo.c:40: error: (Each undeclared identifier is reported only once
rb_cairo.c:40: error: for each function it appears in.)
rb_cairo.c:40: error: `CAIRO_VERSION_MINOR' undeclared (first use in this functi
on)
rb_cairo.c:40: error: `CAIRO_VERSION_MICRO' undeclared (first use in this functi
on)
rb_cairo.c: In function `Init_cairo':
rb_cairo.c:59: error: `CAIRO_VERSION_MAJOR' undeclared (first use in this functi
on)
rb_cairo.c:60: error: `CAIRO_VERSION_MINOR' undeclared (first use in this functi
on)
rb_cairo.c:61: error: `CAIRO_VERSION_MICRO' undeclared (first use in this functi
on)
rb_cairo.c:63: 警告: implicit declaration of function `cairo_version'
make: *** [rb_cairo.o] エラー 1
Gem files will remain installed in /usr/include/cairo/th-opt-include=/usr/includ
e/cairo/gems/cairo-1.10.1 for inspection.
Results logged to /usr/include/cairo/th-opt-include=/usr/include/cairo/gems/cair
o-1.10.1/ext/cairo/gem_make.out
どうやら
rb_cairo.h:20:19: cairo.h: No such file or directory
cairo.hの場所が分かってないらしい
こちらに解決策が書いてありました。
gem install のオプションとして、–with-opt-include=/usr/include/cairo を指定した。
なので
$ gem install cairo -- --with-opt-include=/usr/include/cairo
として実行。
無事インストールされる。
テスト
$ irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'cairo'
LoadError: no such file to load -- cairo.so
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:59:in `gem_o
riginal_require'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:59:in `requi
re'
from /usr/lib/ruby/gems/1.8/gems/cairo-1.10.1-x86-mingw32/lib/cairo.rb:4
6
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:59:in `gem_o
riginal_require'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:59:in `requi
re'
from (irb):2
from (null):0
irb(main):003:0> require 'cairo'
LoadError: no such file to load -- cairo.so
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:59:in `gem_o
riginal_require'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:59:in `requi
re'
from /usr/lib/ruby/gems/1.8/gems/cairo-1.10.1-x86-mingw32/lib/cairo.rb:4
6
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_o
riginal_require'
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `requi
re'
from (irb):3
from (null):0
irb(main):004:0> exit
まだcairo.soが見つからないといわれる。
なんでかなーって思っていたけど、最初にインストールしたx86-mingw32のrcairoが邪魔なのだと思ったので
x86-mingw32のほうだけアンインストール。
$ gem uninstall cairo
Select gem to uninstall:
1. cairo-1.10.1
2. cairo-1.10.1-x86-mingw32
3. All versions
> 2
Successfully uninstalled cairo-1.10.1-x86-mingw32
再度テスト
$ irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'cairo'
=> true
irb(main):003:0> exit
成功した。