首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 相關知識

AIX 5.3 編譯安裝 PHP 5.2.8:pcre 編譯錯誤完美解決

     編輯:PHP 相關知識

在 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 已被定義或衝突,導致編譯器解析失敗。

解決方案:正確的 configure 參數 + 環境變數

關鍵在於:使用系統已安裝的 PCRE 庫(而非 PHP 內建),並正確設定編譯器路徑與標誌。

1. 確保前置依賴已安裝(AIX Toolbox / RPM)

# 安裝 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 安裝。

2. 設定環境變數(關鍵步驟)

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 溢位問題。

3. 正確的 configure 命令(經驗證可編譯通過)

./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/freewareAIX 系統 iconv 功能不全,需 GNU libiconv。

4. 編譯安裝

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 等模組

常見坑點與避坑指南

  • 不要手動複製 .loT 檔案:這只會掩蓋症狀,後續會報更多 pcre_compile.lo、pcre_exec.lo 等錯誤。
  • 避免使用 xlC (IBM Visual Age C++) 編譯 PHP:GCC 相容性最好,xlC 需大量補丁。
  • --disable-static + --enable-shared:生成動態模組 .so,便於 Apache LoadModule 載入。
  • Apache 為 IBM HTTP Server (IHS) 時:確保 IHS 也是 64 位、啟用 ZTS,且 apxs 路徑正確(或手動配置 LoadModule php5_module /usr/local/php5.2.8/libphp5.so)。
  • 參考資源:Installing PHP 5 on AIX using IBM HTTP Server(本方案核心參考)。

總結

AIX 編譯 PHP 核心難點在於系統庫版本舊、型別定義衝突、工具鏈非 GNU 標準。解決之道:全面使用 AIX Toolbox (GNU) 工具鏈與庫、指定 --with-pcre-regex 使用系統 PCRE、設定正確的 64 位編譯標誌。按上述流程操作,PHP 5.2.8 可在 AIX 5.3/6.1/7.x 上穩定編譯通過並運行。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved