PHP没有在构建时正确链接MySQL共享库

时间:2011-08-30 22:20:34

标签: php mysql makefile shared-libraries

我正在尝试使用此配置在我的新计算机上构建PHP:

export MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS="-arch x86_64" CXXFLAGS="-arch x86_64" LIBS=-lresolv
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib
./configure --prefix=/usr/local --with-apxs2=/usr/sbin/apxs --with-ldap=/usr --with-kerberos=/usr --enable-cli --with-zlib-dir=/usr --enable-exif --enable-ftp --enable-mbstring --enable-mbregex --enable-sockets --with-iodbc=/usr --with-curl=/usr --with-config-file-path=/etc --sysconfdir=/private/etc --with-mysql-sock=/var/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql=/usr/local/mysql --with-openssl=/usr --with-xmlrpc --with-xsl=/usr --without-pear --with-libxml-dir=/usr --with-iconv=/usr/local --with-pdo-mysql=/usr/local/mysql/bin/mysql_config --with-gd --with-jpeg-dir=/usr/local/Cellar --with-png-dir=/usr/X11 --with-freetype-dir=/usr/X11 --with-mcrypt=/usr/local/Cellar --enable-pcntl

配置运行正常,但是当我尝试运行“make”时,它最终会出现此错误:

Generating phar.phar
dyld: Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Users/mdiamond/Downloads/php-5.3.8/sapi/cli/php
  Reason: image not found
make: *** [ext/phar/phar.phar] Trace/BPT trap: 5

考虑到我指定了“export DYLD_LIBRARY_PATH = / usr / local / mysql / lib”并且libmysqlclient.18.dylib在该路径中,这非常奇怪。似乎链接器正在寻找没有路径的libmysqlclient.18.dylib(在根目录中?)。我还在我的php二进制文件上运行了otool并得到了这个:

/usr/lib/libexslt.0.dylib (compatibility version 9.0.0, current version 9.13.0)
/usr/lib/libiodbc.2.dylib (compatibility version 4.0.0, current version 4.18.0)
libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
/usr/local/lib/libmcrypt.4.dylib (compatibility version 9.0.0, current version 9.8.0)
/usr/local/lib/libltdl.7.dylib (compatibility version 11.0.0, current version 11.0.0)
/System/Library/Frameworks/LDAP.framework/Versions/A/LDAP (compatibility version 1.0.0, current version 2.2.0)
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/X11/lib/libfreetype.6.dylib (compatibility version 13.0.0, current version 13.2.0)
/usr/X11/lib/libpng15.15.dylib (compatibility version 17.0.0, current version 17.0.0)
/usr/local/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/usr/local/lib/libjpeg.8.dylib (compatibility version 12.0.0, current version 12.0.0)
/usr/lib/libcrypto.0.9.8.dylib (compatibility version 0.9.8, current version 0.9.8)
/usr/lib/libssl.0.9.8.dylib (compatibility version 0.9.8, current version 0.9.8)
/usr/lib/libcurl.4.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0)
/usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 46.0.0)
/usr/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.3.0)
/usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 46.1.0)
/System/Library/Frameworks/Kerberos.framework/Versions/A/Kerberos (compatibility version 5.0.0, current version 6.0.0)
/usr/lib/libxslt.1.dylib (compatibility version 3.0.0, current version 3.24.0)

请注意libmysqlclient是唯一没有路径的库。有谁知道我怎么解决这个问题?我运行配置错了吗?

3 个答案:

答案 0 :(得分:2)

我遇到了类似的问题,我认为这与/usr/local/mysql符号链接到我的计算机上的/usr/local/mysql-5.5.15-osx10.6-x86_64(通过DMG安装的MySQL)有关。更改DYLD_LIBRARY_PATH以使用完全限定的路径似乎让make对我有效。

但是,我在make install过程中确实遇到了后续问题。在Installing PEAR environment步骤中出现了相同的错误消息。 问题的解决方案是事先做到这一点:

install_name_tool -change libmysqlclient.18.dylib \
  /usr/local/mysql-5.5.15-osx10.6-x86_64/lib/libmysqlclient.18.dylib \
  /path/to/php-5.3.8/sapi/cli/php

答案 1 :(得分:1)

当我尝试在MacOS X 10.6.8 Snow Leopard上与MariaDB 5.5一起编译PHP 5.4.16时,发生了类似的事情。在make期间,此过程意外停止并显示此错误报告:

Undefined symbols:
 "_res_9_dn_expand", referenced from:
 _php_parserr in dns.o
 _php_parserr in dns.o
 _php_parserr in dns.o
 _php_parserr in dns.o
 _php_parserr in dns.o
 _php_parserr in dns.o
 _php_parserr in dns.o
 _zif_dns_get_mx in dns.o
 "_res_9_search", referenced from:
 _zif_dns_check_record in dns.o
 _zif_dns_get_mx in dns.o
 _zif_dns_get_record in dns.o
 "_res_9_init", referenced from:
 _zif_dns_check_record in dns.o
 _zif_dns_get_mx in dns.o
 _zif_dns_get_record in dns.o
 "_res_9_dn_skipname", referenced from:
 _zif_dns_get_mx in dns.o
 _zif_dns_get_mx in dns.o
 _zif_dns_get_record in dns.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1

我正在使用一大堆非标准目录来运行我的服务器(带有PHP-CGI的apache),因此我的配置设置有点奇怪而且对其他人没有帮助。他们使用MariaDB 5.2为PHP的整个5.4分支工作,直到今天才停止按预期工作。

感谢您的帖子,这就是我想到的,让它再次成功编译和安装(当然,根据自己的要求更改路径):

  1. compile之前,设置数据库lib目录的路径:

    export DYLD_LIBRARY_PATH=/customserver/maria55/lib

  2. 根据需要使用选项运行./compile

  3. 运行make
  4. 运行此命令来修复CGI和CLI二进制文件中mysql客户端库的损坏路径:

    install_name_tool -change install_name_tool -change libmysqlclient.18.dylib /customserver/maria55/lib/libmysqlclient.18.dylib /sources/php-5.4.16/sapi/cli/php

    install_name_tool -change libmysqlclient.18.dylib /customserver/maria55/lib/libmysqlclient.18.dylib /sources/php-5.4.16/sapi/cgi/php-cgi

  5. 运行sudo make install

  6. 希望这对同样情况下的其他人有帮助

答案 2 :(得分:0)

第二个_php_parserr in dns.o错误(提及herehere)也可以通过执行以下操作来解决:

修改您的Makefile并将以下标记添加到EXTRA_LIBS =部分(除了已存在的其他标记):

EXTRA_LIBS = -lsresolv

虽然如果你可以通过改变你的路径来解决它,如上所述,那将是更可取的。