编译php7.1.4出现 undefined reference to isfinite

来源:互联网 发布:电脑还原卡软件 编辑:程序博客网 时间:2024/06/07 05:01

我在 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' followcollect2: ld returned 1 exit statusmake: *** [sapi/cli/php] Error 1

系统信息 :

[root@localhost]# cat /etc/issueCentOS release 5.5 (Final)Kernel \r on an \m[root@localhost]# gcc --versiongcc (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 NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.[root@localhost]# ldd --versionldd (GNU libc) 2.5Copyright (C) 2006 Free Software Foundation, Inc.This is free software; see the source for copying conditions.  There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Written by Roland McGrath and Ulrich Drepper.[root@localhost]# autoconf --versionautoconf (GNU Autoconf) 2.59Written 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 NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.[root@localhost]# m4 --versionGNU M4 1.4.5Written by Rene' Seindal.Copyright (C) 2006 Free Software Foundation, Inc.This is free software; see the source for copying conditions.  There is NOwarranty; 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.logconfigure:95485: checking for isfiniteconfigure: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.logconfigure:95505: checking whether isfinite is declaredconfigure:95505: gcc -m32 -c -I/usr/include -g -O2 -fvisibility=hidden -pthread  -D_REENTRANT conftest.c >&5configure: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 后续版本能修复这个问题.

0 0