編譯php7.1.4出現 undefined reference to isfinite

我在 CentOS5.5 上編譯 php7.1.4 出現錯誤:

ext/standard/.libs/var.o: In function `php_var_export_ex':
/PHP/32/source/php7.1.4_zts/ext/standard/var.c:473: undefined reference to `isfinite'
main/.libs/php_variables.o: In function `zend_dval_to_lval':
/PHP/32/source/php7.1.4_zts/Zend/zend_operators.h:117: undefined reference to `isfinite'
Zend/.libs/zend_operators.o: In function `zendi_smart_strcmp':
/PHP/32/source/php7.1.4_zts/Zend/zend_operators.c:2789: undefined reference to `isfinite'
Zend/.libs/zend_operators.o: In function `zend_dval_to_lval':
/PHP/32/source/php7.1.4_zts/Zend/zend_operators.h:117: undefined reference to `isfinite'
/PHP/32/source/php7.1.4_zts/Zend/zend_operators.h:117: undefined reference to `isfinite'
Zend/.libs/zend_operators.o:/PHP/32/source/php7.1.4_zts/Zend/zend_operators.h:117: more undefined references to `isfinite' follow
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1

系統信息 :

[root@localhost]# cat /etc/issue
CentOS release 5.5 (Final)
Kernel \r on an \m

[root@localhost]# gcc --version
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@localhost]# ldd --version
ldd (GNU libc) 2.5
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

[root@localhost]# autoconf --version
autoconf (GNU Autoconf) 2.59
Written by David J. MacKenzie and Akim Demaille.
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@localhost]# m4 --version
GNU M4 1.4.5
Written by Rene' Seindal.
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

網上找了一圈發現 GCC 4.1.2 版本還不能支持 isfinite, GCC4.3.3 纔開始支持 isfinite.

但是我又不想升級 GCC,那是否還有其他方法呢?

經過測試, php7.1.2 之前的版本都可以編譯通過,php7.1.3之後的版本一編譯就報上面的錯誤

我的配置參數爲 :

./configure --prefix=/target/php --with-config-file-path=/target/php/etc --enable-maintainer-zts --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session

爲什麼 php7.1.2 可以編譯通過,而 php7.1.3 之後的版本就不行了呢?

我對比了 php7.1.2 和 php7.1.3 的 config.log :

>>> php7.1.2 config.log
configure:95485: checking for isfinite
configure:95485: gcc -m32 -o conftest -I/usr/include -g -O2 -fvisibility=hidden -pthread  -D_REENTRANT  conftest.c  >&5
/tmp/ccsJhzxB.o: In function `main':
/usr/local/src/php-7.1.2/conftest.c:514: undefined reference to `isfinite'
.....
ac_cv_func_isfinite=no


>>> php7.1.3 config.log
configure:95505: checking whether isfinite is declared
configure:95505: gcc -m32 -c -I/usr/include -g -O2 -fvisibility=hidden -pthread  -D_REENTRANT conftest.c >&5
configure:95505: $? = 0
.....
#define HAVE_DECL_ISFINITE 1
.....
ac_cv_have_decl_isfinite=yes

通過觀察可以發現 php7.1.2 的 configure 腳本可以正確檢測 gcc 是否支持 isfinite

而 php7.1.3 之後的腳本總是檢測出 gcc 能夠支持 isfinite

OK,那就修改 configure 使其認爲 gcc 不支持 isfinite 是否就行了呢?

在 php7.1.3 版本你需要修改configure文件使其沒有定義 HAVE_DECL_ISFINITE 等幾個宏纔可以

推薦修改 php7.1.4 版本的 configure 文件,因爲 php7.1.4 打過一個補丁

https://github.com/php/php-src/commit/2e8308260513015dbf80ff0239eca79dbca4f36e

修改 php7.1.4 的 configure 文件的 95508、95519 和 95530 行

ac_have_decl=1 修改爲 ac_have_decl=0

 95505  ac_fn_c_check_decl "$LINENO" "isfinite" "ac_cv_have_decl_isfinite" "#include <math.h>
 95506  "
 95507  if test "x$ac_cv_have_decl_isfinite" = xyes; then :
 95508    ac_have_decl=1    #修改爲 ac_have_decl=0
 95509  else
 95510    ac_have_decl=0
 95511  fi
 95512  
 95513  cat >>confdefs.h <<_ACEOF
 95514  #define HAVE_DECL_ISFINITE $ac_have_decl
 95515  _ACEOF
 95516  ac_fn_c_check_decl "$LINENO" "isnan" "ac_cv_have_decl_isnan" "#include <math.h>
 95517  "
 95518  if test "x$ac_cv_have_decl_isnan" = xyes; then :
 95519    ac_have_decl=1    #修改爲 ac_have_decl=0
 95520  else
 95521    ac_have_decl=0
 95522  fi
 95523  
 95524  cat >>confdefs.h <<_ACEOF
 95525  #define HAVE_DECL_ISNAN $ac_have_decl
 95526  _ACEOF
 95527  ac_fn_c_check_decl "$LINENO" "isinf" "ac_cv_have_decl_isinf" "#include <math.h>
 95528  "
 95529  if test "x$ac_cv_have_decl_isinf" = xyes; then :
 95530    ac_have_decl=1    #修改爲 ac_have_decl=0
 95531  else
 95532    ac_have_decl=0
 95533  fi

修改之後可以看到 config.log 中

| #define HAVE_DECL_ISFINITE 0
| #define HAVE_DECL_ISNAN 0
| #define HAVE_DECL_ISINF 0

然後 make 一下,php7.1.4 果然可以正常編譯了。當然這只是臨時辦法,還是期待 php 後續版本能修復這個問題.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章