【问题标题】:PHP isn't linking MySQL shared library correctly on buildPHP 在构建时未正确链接 MySQL 共享库
【发布时间】:2011-11-07 04:57:56
【问题描述】:

我正在尝试使用此配置在我的新计算机上构建 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 是唯一没有路径的库。有谁知道我该如何解决这个问题?我运行配置错误吗?

【问题讨论】:

    标签: php mysql makefile shared-libraries


    【解决方案1】:

    我遇到了类似的问题,我认为这与/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
    

    【讨论】:

      【解决方案2】:

      当我尝试在 MacOS X 10.6.8 Snow Leopard 上编译 PHP 5.4.16 和 MariaDB 5.5 时,发生了类似的事情。在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

      希望这对其他处于相同情况的人有所帮助

      【讨论】:

        【解决方案3】:

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

        编辑您的 Makefile 并将以下标志添加到 EXTRA_LIBS = 部分(除了已经存在的其他标志):

        EXTRA_LIBS = -lsresolv
        

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

        【讨论】:

          猜你喜欢
          • 2012-05-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-11-13
          • 2012-03-20
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多