研究で引き継いだプログラムをリプレイスするべく、WindowsでのRoR環境をあれこれいじっていた。 もともとのプログラムが使っていたので、MySQLを使うことにした。
ここで、mysql2モジュールのgem installでエラーがでた。
$ gem install mysql2 Fetching: mysql2-0.3.13.gem (100%) Temporarily enhancing PATH to include DevKit... Building native extensions with: '--with-mysql-dir=C:\Program Files\MySQL\MySQLServer 5.5' This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. C:/Ruby200/bin/ruby.exe extconf.rb --with-mysql-dir=C:\Program Files\MySQL\MySQL Server 5.5 checking for rb_thread_blocking_region()... yes checking for rb_wait_for_single_fd()... yes checking for rb_hash_dup()... yes checking for rb_intern3()... yes checking for main() in -llibmysql... 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/bin/ruby --with-mysql-dir --with-mysql-include --without-mysql-include=${mysql-dir}/include --with-mysql-lib --without-mysql-lib=${mysql-dir}/ --with-mysql-dir --with-mysql-include --without-mysql-include=${mysql-dir}/include --with-mysql-lib --without-mysql-lib=${mysql-dir}/lib --with-libmysqllib --without-libmysqllib Gem files will remain installed in C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13 for inspection. Results logged to C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13/ext/mysql2/gem_make.out
"windows gem mysql2"とかで調べるとStack Overflowにこんな記事があった。
mysql - Cannot install mysql2 gem - Stack Overflow
--with-mysql-dir オプションをつければいいらしいということはわかったのだが、いろいろやってもうまくいかない。
$ gem install mysql2 -- --with-mysql-dir=PATH\TO\MYSQL ERROR: While executing gem ... (OptionParser::InvalidOption) invalid option: --with-mysql-dir=PATH\TO\MYSQL
よく見るとこんなコメントがあった。
I'll add that it may be better to use cmd.exe instead of powershell for these commands. For some reason under powershell gem kept throwing an error that said "invalid option". – Segfault Oct 27 '11 at 15:31
PowerShellを使っていたので、おいおいと思いつつcmd.exeを立ち上げてみる。
$ gem install mysql2 -- --with-mysql-dir=PATH\TO\MYSQL Temporarily enhancing PATH to include DevKit... Building native extensions with: '--with-mysql-dir=PATH\TO\MYSQL' This could take a while... Successfully installed mysql2-0.3.13 Parsing documentation for mysql2-0.3.13 unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/mysql2/mysql2.so, skiping Installing ri documentation for mysql2-0.3.13 1 gem installed
通った。 ちなみに、今回はMySQLがProgram Files(スペースが入っている)にインストールされていたため、下のようなコマンドが正解だった。
$ gem install mysql2 -- '--with-mysql-dir="C:\Program Files\MySQL\MySQL Server 5.5"'
ややこしや…