LoginSignup
12
12

More than 5 years have passed since last update.

WindowsでCygwin Berkshelf3ではまったこと

Last updated at Posted at 2014-05-29

Berkshelfは3系からChef-DKというものに組み込まれたようです。
Windows環境においてはインストーラーはcoming soonと表示されております。
そのため、gemで入れる方法が考えられます。
しかし、gemのインストール時にnative extensionのエラーがでます。


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

    /usr/bin/ruby.exe extconf.rb
-> sh /usr/lib/ruby/gems/1.9.1/gems/dep-selector-libgecode-1.0.1/ext/libgecode3/vendor/gecode-3.7.3/configure --prefix=/usr/lib/ruby/gems/1.9.1/gems/dep-selector-libgecode-1.0.1/lib/dep-selector-libgecode/vendored-gecode --disable-doc-dot --disable-doc-search --disable-doc-tagfile --disable-doc-chm --disable-doc-docset --disable-qt --disable-examples --disable-flatzinc
checking for the host operating system... Windows
checking whether the C++ compiler works... no
configure: error: in `/usr/lib/ruby/gems/1.9.1/gems/dep-selector-libgecode-1.0.1/ext/libgecode3/vendor/gecode-3.7.3':
configure: error: C++ compiler cannot create executables
See `config.log' for more details
extconf.rb:94:in `block in run': Failed to build gecode library. (GecodeBuild::BuildError)
        from extconf.rb:93:in `chdir'
        from extconf.rb:93:in `run'
        from extconf.rb:100:in `'

extconf failed, exit code 1

Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/dep-selector-libgecode-1.0.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.9.1/extensions/x86_64-cygwin/1.9.1/dep-selector-libgecode-1.0.1/gem_make.out

まずは、バージョン指定してそもそも問題回避する方法が考えられます。


gem install berkshelf -v '2.0.16'

ここから下は、Berkshelf3系を使いたい人用になります。

エラーを見る限り、gecodeというものがコンパイルできないようです。
http://www.gecode.org/download.html
よく分からないのでwindows版のgecodeのインストーラーを探したらありましたので入れて見ます。
その上で、事前に依存するdep-selector-libgecode-1.0.1 というパッケージを
以下のように入れました。


$ USE_SYSTEM_GECODE=1 gem install dep-selector-libgecode

そして同じように実行しましたが、今度は違うエラーが出てしっぱいしました。


gem install berkshelf

どうも、
USE_SYSTEM_GECODE=1
をつけること自体はエラーをスキップしただけのようです。

しかも、githubのサイトをみると、gecodeの3.系を使うようにいっています。
windowsのインストーラーが提供されているのは4.x系のようですので、
gecodeの3.xをソースからインストールするしかないということになりそうです。

gecode-3.7.3.tar.gzをダウンロードしてきて、ビルドしてみます。
以下の説明ですと、--mno-cygwinというものしぐいぃんなオプションを設定します。

http://stderr.org/doc/libgecode-doc/html/PageComp.html


$./configure CC="gcc --mno-cygwin" CXX="g++ --mno-cygwin"
checking for the host operating system... Windows
checking whether the C++ compiler works... no
configure: error: in /cygdrive/c/Users/xxxx/gecode-3.7.3:
configure: error: C++ compiler cannot create executables
See `config.log' for more details

config.logをみるとg++の方はいらないようです。
g++: error: unrecognized command line option '--mno-cygwin'

はずしてコンパイルしてみます。ついでに、gemでインストールしてエラーになる際につけているオプションもつけて見ます。


$./configure CC="gcc -mno-cygwin"  --prefix=/usr/lib/ruby/gems/1.9.1/gems/dep-selector-libgecode-1.0.1/lib/dep-selector-libgecode/vendored-gecode --disable-doc-dot --disable-doc-search --disable-doc-tagfile --disable-doc-chm --disable-doc-docset --disable-qt --disable-examples --disable-flatzinc

checking for the host operating system... Windows
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.exe
checking for suffix of executables... .exe
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether /usr/bin/g++ accepts -g... yes
checking for gcc... gcc --mno-cygwin
checking whether we are using the GNU C compiler... no
checking whether gcc --mno-cygwin accepts -g... no
checking for gcc --mno-cygwin option to accept ISO C89... unsupported
checking for ranlib... ranlib
checking for diff... ok
checking for tar... ok
checking for make... ok
checking for sed... ok
checking for perl... ok
checking how to run the C++ preprocessor... /usr/bin/g++ -E
configure: error: Your version of gcc is too old. You need at least version 4.2.

どうも、configureの中を見るとLINENOという数字をみて、versionのエラーを吐いているようです。
gcc48とかそういう名前を前提にしているっぽいです。

また、--mno-cygwinはcygwin.dllに依存しないものをつくりたいときに入れるようですのではずします。


$ cp /usr/bin/gcc.exe /usr/bin/gcc48.exe
$ cp /usr/bin/g++.exe /usr/bin/g++48.exe
$ ./configure CC="gcc48"  \
--prefix=/usr/lib/ruby/gems/1.9.1/gems/dep-selector-libgecode-1.0.1/lib/dep-selector-libgecode/vendored-gecode \
--disable-doc-dot --disable-doc-search --disable-doc-tagfile \
--disable-doc-chm --disable-doc-docset --disable-qt \
--disable-examples --disable-flatzinc
$ make
$ cp libgecode* /lib/
$ cp -r gecode/* /usr/include/

makeにものすごい時間がかります。
make installの先がよく分からないんですが、cygwin的に.aは/lib, .hは/usr/includeのようなので、手動で配置。


$USE_SYSTEM_GECODE=1 gem install berkshelf
Building native extensions.  This could take a while...
Successfully installed dep_selector-1.0.3
Fetching: solve-1.2.0.gem (100%)
Successfully installed solve-1.2.0
Fetching: sawyer-0.5.4.gem (100%)
Successfully installed sawyer-0.5.4
Fetching: octokit-3.1.0.gem (100%)
Successfully installed octokit-3.1.0
Fetching: berkshelf-3.1.2.gem (100%)
Successfully installed berkshelf-3.1.2
Parsing documentation for berkshelf-3.1.2
Installing ri documentation for berkshelf-3.1.2
Parsing documentation for dep_selector-1.0.3
Installing ri documentation for dep_selector-1.0.3
Parsing documentation for octokit-3.1.0
Installing ri documentation for octokit-3.1.0
Parsing documentation for sawyer-0.5.4
Installing ri documentation for sawyer-0.5.4
Parsing documentation for solve-1.2.0
Installing ri documentation for solve-1.2.0
Done installing documentation for berkshelf, dep_selector, octokit, sawyer, solve after 12 seconds
5 gems installed

何とか入ったようです。

環境についてメモ


$apt-cyg find ruby
ruby
ruby-json
ruby-rake
ruby-rdoc

試行錯誤した結果ですのでもしかしたら再現性低いかもしれません。

12
12
5

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
12
12