在 AIX 5.3/6.1 上從源碼編譯 PHP 5.2.8 時,make 階段頻繁報錯 ext/pcre/pcrelib/pcre_chartables.lo Error 1、pcre_compile.lo Error 1,且伴隨 pcre_internal.h: expected specifier-qualifier-list before 'BOOL' 等標頭檔錯誤。這是經典的 PCRE 庫與 AIX 系統標頭檔衝突問題。本文提供經實測可行的完整編譯配置方案。
In file included from .../pcre_chartables.c:25:
.../pcre_internal.h:976: error: expected specifier-qualifier-list before 'BOOL'
.../pcre_internal.h:1027: error: expected specifier-qualifier-list before 'BOOL'
.../pcre_internal.h:1137: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'php__pcre_is_newline'
make: *** [ext/pcre/pcrelib/pcre_chartables.lo] Error 1
核心原因:PHP 內建的 PCRE 庫(ext/pcre/pcrelib/)中的 pcre_internal.h 使用了 BOOL 型別,而在 AIX 系統標頭檔(sys/types.h 等)中 BOOL 已被定義或衝突,導致編譯器解析失敗。
關鍵在於:使用系統已安裝的 PCRE 庫(而非 PHP 內建),並正確設定編譯器路徑與標誌。
# 安裝 GNU 工具鏈與庫
yum install gcc make libtool autoconf automake m4 \
pcre-devel pcre-static \
libxml2-devel libxml2-static \
zlib-devel zlib-static \
bzip2-devel \
freetype-devel \
libpng-devel \
libjpeg-devel \
gd-devel \
openssl-devel \
curl-devel \
gettext-devel \
icu-devel
或從 AIX Toolbox 下載對應 .rpm 手動 rpm -ivh 安裝。
export PATH=/opt/freeware/bin:/usr/vac/bin:$PATH
export CC=gcc
export CFLAGS="-O2 -q64 -I/opt/freeware/include"
export LDFLAGS="-L/opt/freeware/lib -Wl,-bbigtoc"
export CPPFLAGS="-I/opt/freeware/include"
export PKG_CONFIG_PATH=/opt/freeware/lib/pkgconfig
-q64:生成 64 位目標碼(AIX 5.3+ 預設 32 位,PHP 5.2 建議 64 位)。/opt/freeware:AIX Toolbox 預設安裝前綴,庫與標頭檔均在該路徑。-Wl,-bbigtoc:解決大型程式 TOC 溢位問題。./configure \
--prefix=/usr/local/php5.2.8 \
--with-config-file-path=/usr/HTTPServer/conf/php.ini \
--enable-shared \
--disable-static \
--enable-maintainer-zts \
--enable-calendar \
--enable-bcmath \
--enable-sockets \
--enable-zip \
--with-gd \
--with-zlib \
--with-libxml-dir=/opt/freeware \
--with-zlib-dir=/opt/freeware \
--with-bz2 \
--with-gettext=/opt/freeware \
--with-jpeg-dir=/opt/freeware \
--with-png-dir=/opt/freeware \
--with-freetype-dir=/opt/freeware \
--with-pcre-regex=/opt/freeware \ # 關鍵:使用系統 PCRE
--with-openssl=/opt/freeware \
--with-curl=/opt/freeware \
--enable-mbstring \
--with-iconv=/opt/freeware \
--enable-soap \
--enable-ftp \
--enable-exif
| 參數 | 作用 |
|---|---|
--with-pcre-regex=/opt/freeware | 指示 PHP 使用系統安裝的 PCRE 庫(含 pcre.h、libpcre.a),跳過內建 pcrelib 編譯,徹底避開 BOOL 衝突。 |
--with-libxml-dir=/opt/freeware | 指定 libxml2 路徑,避免系統舊版衝突。 |
--enable-maintainer-zts | 啟用線程安全(ZTS),Apache 2 worker MPM / IBM HTTP Server 需要。 |
--with-iconv=/opt/freeware | AIX 系統 iconv 功能不全,需 GNU libiconv。 |
make -j$(nproc) # 並行編譯加速
make install
/usr/local/php5.2.8/bin/php -v
/usr/local/php5.2.8/bin/php -m | grep -E 'pcre|xml|gd|mbstring|zip'
# 輸出應包含 pcre, xml, gd, mbstring, zip 等模組
pcre_compile.lo、pcre_exec.lo 等錯誤。--disable-static + --enable-shared:生成動態模組 .so,便於 Apache LoadModule 載入。apxs 路徑正確(或手動配置 LoadModule php5_module /usr/local/php5.2.8/libphp5.so)。AIX 編譯 PHP 核心難點在於系統庫版本舊、型別定義衝突、工具鏈非 GNU 標準。解決之道:全面使用 AIX Toolbox (GNU) 工具鏈與庫、指定 --with-pcre-regex 使用系統 PCRE、設定正確的 64 位編譯標誌。按上述流程操作,PHP 5.2.8 可在 AIX 5.3/6.1/7.x 上穩定編譯通過並運行。