LoginSignup
2
2

More than 5 years have passed since last update.

libxml-ruby を ruby 2.0 の (32|64)bit windows OS にインストールする方法

Last updated at Posted at 2014-03-30
gem i libxml-ruby

として、インストールされるのに

require 'libxml'

とすると

C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53:in `require': cannot load such file -- libxml_ruby (LoadError)

となり、使えません。
いったいどうすれば。。。

結論(32bit)

結論 64bit に記載したサイトで32bit版を取得し、以下のコマンドを入力

ダウンロード元リンク (64bit版じゃない方をダウンロードする)
ftp://ftp.zlatkovic.com/libxml/64bit/

gem i libxml-ruby --platform=ruby -- --with-zlib-include=C:\opt\zlib\include --with-zlib-lib=C:\opt\zlib\lib --with-iconv-include=C:\opt\iconv\include --with-iconv-lib=C:\opt\iconv\lib --with-xml2-include=C:\opt\libxml2\include\libxml2 --with-xml2-lib=C:\opt\libxml2\lib

各パスは自身の展開したパスにする。( もしかするとバックスラッシュはちゃんと動いてくれないときがあるかも?スラッシュだとOK? )

その後、各dllをrubyのbinフォルダにコピー。これで問題なく動作しました。


64bit Windows OS にインストールする場合には、native extension をインストールするところでこける。

C:\Users\*******\Documents\src\libxml-ruby\libxml-ruby-2.7.0>gem i --local libxml-ruby-2.7.0.gem -- --with-zlib-includ
e=C:\Users\*******\Documents\src\zlib-1.2.8 --with-zlib-lib=C:\Users\*******\Documents\src\zlib-1.2.8
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-zlib-include=C:\Users\*******\Documents\src\zlib-1.2.8 --with-zlib-lib=C:\Use
rs\*******\Documents\src\zlib-1.2.8'
This could take a while...
ERROR:  Error installing libxml-ruby-2.7.0.gem:
        ERROR: Failed to build gem native extension.

    C:/Ruby200-x64/bin/ruby.exe extconf.rb --with-zlib-include=C:\Users\*******\Documents\src\zlib-1.2.8 --with-zlib-l
ib=C:\Users\*******\Documents\src\zlib-1.2.8
C:\Users\*******\Documents\src\zlib-1.2.8
C:\Users\*******\Documents\src\zlib-1.2.8
checking for socket() in -lsocket... no
checking for gethostbyname() in -lnsl... no
checking for atan() in -lm... yes
checking for inflate() in -lz... no
checking for inflate() in -lzlib... no
checking for inflate() in -lzlib1... no
checking for inflate() in -llibz... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/Ruby200-x64/bin/ruby
        --with-iconv-dir
        --without-iconv-dir
        --with-iconv-include
        --without-iconv-include=${iconv-dir}/include
        --with-iconv-lib
        --without-iconv-lib=${iconv-dir}/
        --with-zlib-dir
        --without-zlib-dir
        --with-zlib-include=${zlib-dir}/include
        --with-zlib-lib=${zlib-dir}/
        --with-socketlib
        --without-socketlib
        --with-nsllib
        --without-nsllib
        --with-mlib
        --without-mlib
        --with-zlib
        --without-zlib
        --with-zliblib
        --without-zliblib
        --with-zlib1lib
        --without-zlib1lib
        --with-libzlib
        --without-libzlib
 extconf failure: need zlib


Gem files will remain installed in C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/libxml-ruby-2.7.0 for inspection.
Results logged to C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/libxml-ruby-2.7.0/ext/libxml/gem_make.out

これを解決するためには、zlibを64bit版でビルドして、パスを通すと良い。

こっからソースとってきて

%{展開したフォルダ}/win32 の Makefile.msc をちょろっと変更

LDFLAGS = -nologo -machine:x64 -debug -incremental:no -opt:ref

Makefile.msc に記載されている通りにnmake

nmake -f win32/Makefile.msc AS=ml64 LOC="-DASMV -DASMINF -I." OBJA="inffasx64.obj gvmat64.obj inffas8664.obj"

%{展開したフォルダ} にzlib1.dllが出来上がるので、ruby の bin に入れる。

そして、gem i libxml-ruby -- --with-zlib-include=%{展開したzlibフォルダ} --with-zlib-lib=%{展開したzlibフォルダ}とすると

C:\Users\*******\Documents\src\libxml-ruby\libxml-ruby-2.7.0>gem i --local libxml-ruby-2.7.0.gem -- --with-zlib-includ
e=C:\Users\*******\Documents\src\zlib-1.2.8 --with-zlib-lib=C:\Users\*******\Documents\src\zlib-1.2.8
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-zlib-include=C:\Users\*******\Documents\src\zlib-1.2.8 --with-zlib-lib=C:\Use
rs\*******\Documents\src\zlib-1.2.8'
This could take a while...
ERROR:  Error installing libxml-ruby-2.7.0.gem:
        ERROR: Failed to build gem native extension.

    C:/Ruby200-x64/bin/ruby.exe extconf.rb --with-zlib-include=C:\Users\*******\Documents\src\zlib-1.2.8 --with-zlib-l
ib=C:\Users\*******\Documents\src\zlib-1.2.8
C:\Users\*******\Documents\src\zlib-1.2.8
C:\Users\*******\Documents\src\zlib-1.2.8
checking for socket() in -lsocket... no
checking for gethostbyname() in -lnsl... no
checking for atan() in -lm... yes
checking for inflate() in -lz... no
checking for inflate() in -lzlib... no
checking for inflate() in -lzlib1... yes
checking for iconv_open() in -liconv... no
checking for libiconv_open() in -liconv... no
checking for libiconv_open() in -llibiconv... no
checking for iconv_open() in -llibiconv... no
checking for iconv_open() in -lc... no
checking for iconv_open() in -lrecode... no
checking for main() in -liconv... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/Ruby200-x64/bin/ruby
        --with-iconv-dir
        --without-iconv-dir
        --with-iconv-include
        --without-iconv-include=${iconv-dir}/include
        --with-iconv-lib
        --without-iconv-lib=${iconv-dir}/
        --with-zlib-dir
        --without-zlib-dir
        --with-zlib-include=${zlib-dir}/include
        --with-zlib-lib=${zlib-dir}/
        --with-socketlib
        --without-socketlib
        --with-nsllib
        --without-nsllib
        --with-mlib
        --without-mlib
        --with-zlib
        --without-zlib
        --with-zliblib
        --without-zliblib
        --with-zlib1lib
        --without-zlib1lib
        --with-iconvlib
        --without-iconvlib
        --with-iconvlib
        --without-iconvlib
        --with-libiconvlib
        --without-libiconvlib
        --with-libiconvlib
        --without-libiconvlib
        --with-clib
        --without-clib
        --with-recodelib
        --without-recodelib
        --with-iconvlib
        --without-iconvlib
 extconf failure: need libiconv.

Install the libiconv or try passing one of the following options
to extconf.rb:

  --with-iconv-dir=/path/to/iconv
  --with-iconv-lib=/path/to/iconv/lib
  --with-iconv-include=/path/to/iconv/include



Gem files will remain installed in C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/libxml-ruby-2.7.0 for inspection.
Results logged to C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/libxml-ruby-2.7.0/ext/libxml/gem_make.out

次はiconvでこける。

iconvは以下から取得

VisualStudio は "is no longer supported." らしいので MinGWを入れて、msys上でコンパイルする

./configure --host=x86_64-w64-mingw32 --prefix=/usr/local/mingw CC=x86_64-w64-mingw32-gcc-4.5.4 AR=x86_64-w64-mingw32-ar CPPFLAGS=-Wall -I/usr/local/mingw/include LDFLAGS=-L/usr/local/mingw/lib

ARは必要ないかもだけど、念のため入れてる。

終わったら make する。私の環境だと途中でエラー ar コマンドがないと怒られる。srclib内の Makefile の AR=ar を変更

AR=x86_64-w64-mingw32-ar

再度 make して保存。

bin, lib/.libs にできている libcharset-1.dll と libiconv-2.dll を %{RUBYインストールフォルダ}/bin にコピー

gem のオプション --with-iconv-include と --with-iconv-lib を指定して インストール

gem i --local libxml-ruby-2.7.0.gem -- --with-zlib-includ
e=%{zlibを展開したルートフォルダ} --with-zlib-lib=%{zlibを展開したルートフォルダ} --with-iconv-include=%{iconvを展開したルートフォルダ}\include --with-iconv-lib=%{iconvを展開したルートフォルダ}\lib\.libs

%{...} は適宜読み替えてください。

を実行。でも次は libxml2 を入れてくれと言われこける。

以下からlibxml2のソースを取得

適当なフォルダに解答し、win32フォルダに移動。おもむろにVS2013 x64 Native Tools コマンド プロンプトを起動し、以下のコマンドを入力

cscript configure.js compiler=msvc include=.\..\libiconv-1.14\include lib=..\..\libiconv-1.14\lib\.libs

include には libiconvのincludeパスを指定する
libにはlibiconvのlibパスを指定する

次に同フォルダの Makefile.msvc を修正

!if "$(WITH_ICONV)" == "1"
LIBS = $(LIBS) libiconv.dll.a

んで、make

nmake -f Makefile.msvc

win32\bin.msvc フォルダに dllが出来上がるので、ruby/binフォルダにコピー

再度 gem インストール

C:\Users\Yoshihiko>gem i libxml-ruby -- --with-zlib-include=C:\Users\Yoshihiko\Documents\src\zlib-1.2.8 --with-zlib-lib=
C:\Users\Yoshihiko\Documents\src\zlib-1.2.8 --with-iconv-include=C:\Users\Yoshihiko\MyApps\MinGW\msys\1.0\home\Yoshihiko
\libiconv-1.14\include --with-iconv-lib=C:\Users\Yoshihiko\MyApps\MinGW\msys\1.0\home\Yoshihiko\libiconv-1.14\lib\.libs
--with-xml2-include=C:\Users\Yoshihiko\MyApps\MinGW\msys\1.0\home\Yoshihiko\libxml2-2.9.1\include --with-xml2-lib=C:\Use
rs\Yoshihiko\MyApps\MinGW\msys\1.0\home\Yoshihiko\libxml2-2.9.1\win32\bin.msvc

インストールできた。しかし、スクリプトが動作しない 193: %1 は有効な Win32 アプリケーションではありません。 - C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/libxml-ruby-2.7.0/lib/libxml_ruby.so (LoadError) と言われて怒られる。どうすれば。。。


結論(64bit)

以下のサイトにバイナリデータへのリンクがありました。それを使って事なきを得ました。この二日の苦労はいったい。。。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2