調査目的で、Win32 環境でPostgreSQLをソースコードからコンパイルしようとしている。
PostgreSQLサイトの「
Native Windows FAQ」や、「
PostgreSQL 8.3 Press Kit」を参考にしつつ、コンパイル環境(開発環境)を準備する所からはじめる。
以下の条件で行う。
■実行環境
WindowsXp Sp3 (x86)
■必要な事
コンパイル環境として MinGWとMSYSをセットアップする。
コンパイル時にエラーが発生するので、ソースコード(ヘッダファイル)を修正しながら、無理矢理コンパイルする。
●MinGWとMSYSのダウンロード
コンパイラ「MinGW」と作業環境「MSYS」について、それぞれのセットアップ・ファイルをダウンロードする。
MinGWは「
SOURCEFORGE.NETのMinGWサイト」のMinGW 5.1.4の「
Download リンク」から、セットアップファイル「
MinGW-5.1.4.exe」をダウンロードする。
また、MSYSはSOURCEFORGE.NETのCOREを使ってもよいのだが、今回は
MSYSダウンロードサイトから「MSYS DTK (developer tool kit)」のセットアップファイル「
msysDTK-1.0.1.exe」をダウンロードする。
ページ中央付近で「Install MSYS DTK 1.0 in C:\msys\1.0.」のように記述されている場所が、リンクになっている。
※08.12.09時点では「MinGW」の最新版が「5.1.4」、「MSYS」の最新版が「1.0.11」である。
念のためこのバージョンの直リンクを作っておく。
・MinGW 5.1.4 :
MinGW-5.1.4.exe
・MSYS DTK 1.0 :
msysDTK-1.0.1.exe
●MinGWとMSYSのセットアップ
上記でダウンロードしたファイルを実行し、それぞれセットアップする。
ちなみにMSYSのコンソール画面では「コピー&ペースト」が使えない。これが結構不便なので「
05.ffmpegコンパイル(Win):msys.batの変更」を参考にしながら、「コピー&ペースト」できるようにしておく方がよい。
●PostgreSQLのソースファイルのダウンロード
日本PostgreSQLユーザー会よりPostgreSQLのソースファイルをダウンロードする。
※08.12.09時点では「8.3.5」が最新版のため、アーカイブ・ファイル名は
「
postgresql-8.3.5.tar.gz」。
●解凍と属性変更
ダウンロードしたアーカイブ・ファイルを「
Lhaplus」などを使って解凍する。
ここでは「
C:\postgresql」に解凍したものとし、以下のように展開されるとする。
C:\postgresql\postgresql-8.3.5\postgresql-8.3.5
このディレクトリに「
configure」や「
Makefile」が展開される。
それから、このディレクトリとサブ・ディレクトリの「読み取り専用」属性を外す
(Windows のエクスプローラで一括で外す)。
※Make作業中にファイルにリダイレクトするので読み取り属性を外す必要がある。
●コンフィギュレーション
①MSYSのインストール先(
C:\msys\1.0 など)に配置されている「
msys.bat」を実行し、シェル環境を立ち上げる。このMSYSのシェル環境で、
# cd /c/postgres/postgresql-8.3.5/postgresql-8.3.5
# ./configure --enable-cassert --enable-debug --without-zlib
....
として、Win32用の
Makefile が作成される。
■コンフィギュレーション・エラー
コンフィギュレーションを実行した時に、
configure: error: no acceptable C compiler found in $PATH
というエラーメッセージが表示される場合、
Cコンパイラのディレクトリがサーチ・パスに登録されていない、という事なので
# export PATH=$PATH:/c/MinGW/bin
のように、サーチパスに登録してから再度
configure を実行する。
●コンパイル
# mingw32-make.exe
のようにMakeする。
■コンパイルエラー
コンパイル中にエラーが発生したので記載しておく。
今回は「調査目的」のため「
何はともあれコンパイルを通すのだ!」という方針の下、それぞれ以下のような措置を取った。
〇
libpq-be.h のコンパイルエラー
In file included from c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/security.h:38,
from ../../../src/include/libpq/libpq-be.h:50,
from ../../../src/include/libpq/libpq.h:21,
from be-secure.c:100:
c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/sspi.h:63: error: syntax error before "SECURITY_STRING"
In file included from c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/security.h:39,
from ../../../src/include/libpq/libpq-be.h:50,
from ../../../src/include/libpq/libpq.h:21,
from be-secure.c:100:
c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/ntsecpkg.h:123: error: syntax error before "SECURITY_STRING"
c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/ntsecpkg.h:125: error: syntax error before "LogonServer"
c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/ntsecpkg.h:127: error: syntax error before '}' token
c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/ntsecpkg.h:212: error: syntax error before "SECPKG_NAME_TYPE"
c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/ntsecpkg.h:225: error: syntax error before "SECPKG_NAME_TYPE"
c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/ntsecpkg.h:342: error: syntax error before "PSecurityUserData"
mingw32-make[3]: *** [be-secure.o] Error 1
mingw32-make[3]: Leaving directory `c:/postgresql/postgresql-8.3.5/postgresql-8.3.5/src/backend/libpq'
mingw32-make[2]: *** [libpq-recursive] Error 2
mingw32-make[2]: Leaving directory `c:/postgresql/postgresql-8.3.5/postgresql-8.3.5/src/backend'
mingw32-make[1]: *** [all] Error 2
mingw32-make[1]: Leaving directory `c:/postgresql/postgresql-8.3.5/postgresql-8.3.5/src'
mingw32-make: *** [all] Error 2
というエラーが発生した。
そこで「
[HACKERS] 8.3 .4 + Vista + MingW + initdb = ACCESS_DENIED」を参考に、
ヘッダファイル
「
c:\postgresql\postgresql-8.3.5\postgresql-8.3.5
\src\include\libpq\libpq-be.h」を以下のように変更
48: #ifdef ENABLE_SSPI
49: #define SECURITY_WIN32
50: #include <security.h>
51: #undef SECURITY_WIN32
↓
#ifdef ENABLE_SSPI
#define SECURITY_WIN32
#include <ntsecapi.h> /* <--- この行を追加 */
#include <security.h>
#undef SECURITY_WIN32
〇
ソースファイルの場所・名前を変更
以下の3つのファイルを、移動・リネームする必要がある。
①「
utf8_and_euc_jis_2004.c」が無い
mingw32-make[3]: *** No rule to make target `utf8_and_euc_jis_2004.o', needed by `libutf8_and_euc_jis_2004.dll'. Stop.
mingw32-make[2]: *** [all] Error 2
mingw32-make[2]: Leaving directory `c:/postgresql/postgresql-8.3.5/postgresql-8.3.5/src/backend/utils/mb/conversion_procs'
mingw32-make[1]: *** [all] Error 2
mingw32-make[1]: Leaving directory `c:/postgresql/postgresql-8.3.5/postgresql-8.3.5/src'
mingw32-make: *** [all] Error 2
これは、
「
c:\postgres\postgresql-8.3.5\postgresql-8.3.5
\src\backend\utils\mb\conversion_procs\utf8_and_euc_jis_2004」
内のソースファイル「
utf8_and_euc_jis_2004.c」が、
何故か「
utf8_and_euc_jis_2004.c000644」という名前になっているために発生する。
以下のように、本来のファイル名にリネームする。
# pushd src/backend/utils/mb/conversion_procs
# mv utf8_and_euc_jis_2004.c000644 utf8_and_euc_jis_2004.c
# popd
②「
euc_jis_2004_and_shift_jis_2004.c」が無い
mingw32-make[3]: *** No rule to make target `utf8_and_shift_jis_2004.o', needed by `libutf8_and_shift_jis_2004.dll'. Stop.
mingw32-make[2]: *** [all] Error 2
mingw32-make[2]: Leaving directory `c:/postgresql/postgresql-8.3.5/postgresql-8.3.5/src/backend/utils/mb/conversion_procs'
mingw32-make[1]: *** [all] Error 2
mingw32-make[1]: Leaving directory `c:/postgresql/postgresql-8.3.5/postgresql-8.3.5/src'
mingw32-make: *** [all] Error 2
これは、ソースファイル「
euc_jis_2004_and_shift_jis_2004.c」が、
本来は↓以下のディレクトリに配置されるべきなのだが、
c:\postgres\postgresql-8.3.5\postgresql-8.3.5
\src\backend\utils\mb\conversion_procs\euc_jis_2004_and_shift_jis_2004
何故か、
c:\postgres\postgresql-8.3.5
\backend\utils\mb\conversion_procs\euc_jis_2004_and_shift_jis_2004
に展開されてしまっているために発生する。
これを、以下のように、本来のディレクトリにリネームする。
# mv ../backend/utils/mb/conversion_procs/euc_jis_2004_and_shift_jis_2004/euc_jis_2004_and_shift_jis_2004.c \
src/backend/utils/mb/conversion_procs/euc_jis_2004_and_shift_jis_2004
③「
utf8_and_shift_jis_2004.c」が無い
mingw32-make[3]: *** No rule to make target `utf8_and_shift_jis_2004.o', needed by `libutf8_and_shift_jis_2004.dll'. Stop.
mingw32-make[2]: *** [all] Error 2
mingw32-make[2]: Leaving directory `c:/postgresql/postgresql-8.3.5/postgresql-8.3.5/src/backend/utils/mb/conversion_procs'
mingw32-make[1]: *** [all] Error 2
mingw32-make[1]: Leaving directory `c:/postgresql/postgresql-8.3.5/postgresql-8.3.5/src'
mingw32-make: *** [all] Error 2
これも②とほぼ同様で、ソースファイル「
utf8_and_shift_jis_2004.c」が、
本来のディレクトリ
c:\postgres\postgresql-8.3.5\postgresql-8.3.5
\src\backend\utils\mb\conversion_procs\utf8_and_shift_jis_2004
ではなく、何故か、
c:\postgres\postgresql-8.3.5\
\src\backend\utils\mb\conversion_procs\utf8_and_shift_jis_2004
に展開されてしまっているために発生する。
⇒本来のディレクトリにリネームする。
# mv ../src/backend/utils/mb/conversion_procs/utf8_and_shift_jis_2004/utf8_and_shift_jis_2004.c
src/backend/utils/mb/conversion_procs/utf8_and_shift_jis_2004
〇
SECURITY_STRING が定義されていない
In file included from c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/security.h:38,
from libpq-int.h:57,
from fe-auth.h:18,
from fe-auth.c:48:
c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/sspi.h:63: error: syntax error before "SECURITY_STRING"
In file included from c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/security.h:39,
from libpq-int.h:57,
from fe-auth.h:18,
from fe-auth.c:48:
c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/ntsecpkg.h:123: error: syntax error before "SECURITY_STRING"
c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/ntsecpkg.h:125: error: syntax error before "LogonServer"
c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/ntsecpkg.h:127: error: syntax error before '}' token
c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/ntsecpkg.h:212: error: syntax error before "SECPKG_NAME_TYPE"
c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/ntsecpkg.h:225: error: syntax error before "SECPKG_NAME_TYPE"
c:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/ntsecpkg.h:342: error: syntax error before "PSecurityUserData"
mingw32-make[3]: *** [fe-auth.o] Error 1
mingw32-make[3]: Leaving directory `c:/download/postgresql/source/postgresql-8.3.5/postgresql-8.3.5/src/interfaces/libpq'
mingw32-make[2]: *** [all] Error 2
mingw32-make[2]: Leaving directory `c:/download/postgresql/source/postgresql-8.3.5/postgresql-8.3.5/src/interfaces'
mingw32-make[1]: *** [all] Error 2
mingw32-make[1]: Leaving directory `c:/download/postgresql/source/postgresql-8.3.5/postgresql-8.3.5/src'
mingw32-make: *** [all] Error 2
sspi.h のコンパイル時に、
SECURITY_STRINGが定義されていないと叱られる。
原因は良く分からないが、以下のように対処する。
「
c:\MinGW\include\sspi.h」を以下のように編集する。
60: #ifndef _NTDEF_H /* 以下の3行を追加 */
61: #include <ntdef.h>
62: #endif
以上のような方法で、
postgresql.exe や
libpq.dll、
psql.exe などをコンパイルできた。
ちなみに、今回初めてMSYSを使ってみたが、MSYSのCOREを使えばインストールしなくても使えるので結構便利です。
|
IT-ソフトウェア関連::ツール類 | 08:36 AM | comments (x) | trackback (x) |