Windowsでruby-pgをコンパイルする

PostgreSQL用のRubyアダプタは、Rubyで書かれたpostgres-prと、Cで書かれたライブラリがありますが、Cで書かれた方は、名前がpostgres、ruby-postgres、ruby-pg、pgところころかわった上、Windows用のバイナリが提供されなくなったため、Windowsでは使いにくくRailsではMySQLが好まれる一因になっているような気がします。

一時はpgのメンテナがWindowsでコンパイルできる人を募集するなどしていたようですが、最近ではバイナリパッケージは出ていないものの、Windowsでのコンパイル方法がフォーラムで紹介されるなど、状況が改善されてきています。

http://www.microsoft.com/japan/msdn/vstudio/express/

私もいろいろ試してみたところ、最新版では通常のgemでもコンパイル導入ができるようなので、紹介しておきます。

1. PostgreSQLのインストール

最新版の8.3.5-1をインストールします。インストールオプションで開発用のモジュール(インクルードファイルとライブラリ)を追加しておきます。

2. Visual C++ 2008 Express Editionのインストール

下記のページから、Visual C++ 2008 Express Editionをダウンロードし、インストールします。 http://www.microsoft.com/japan/msdn/vstudio/express/

3. Rubyのconfig.hの修正

Ruby 1.8.6のヘッダファイルconfig.hには、Visual C++のバージョンを6.0に限定する下記のディレクティブが含まれているため、これをコメントアウトします。

/*
#if _MSC_VER != 1200
#error MSC version unmatch
#endif
*/

4. gemのインストール

環境変数を利用するため、Windowでスタート>すべてのプログラム>Microsoft Visual C++ 2008 Express Edition>Visual Studio Tools>Visual Studio コマンド プロンプトを起動します。 このコマンドプロンプトからgemをインストールします。

>gem install pg
Building native extensions.  This could take a while...
Successfully installed pg-0.7.9.2008.10.13
1 gem installed
Installing ri documentation for pg-0.7.9.2008.10.13...
Installing RDoc documentation for pg-0.7.9.2008.10.13...
のようにインストールできればOKです。

This entry was posted on Fri, 28 Nov 2008 13:12:00 GMT and Posted in . You can follow any any response to this entry through the Atom feed. You can leave a comments, Or a trackback from your own site.
Tags , , , ,


Trackbacks

Use the following link to trackback from your own site:
http://rails.to/trackbacks?article_id=compile-pg-on-windows&day=28&month=11&year=2008

Comments

Leave a response

Leave a comment