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

发布于 2024-12-02 08:10:25 字数 3178 浏览 0 评论 0原文

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

I'm trying to build PHP on my new computer with this configuration:

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

The configuration runs fine, but when I try to run "make" it ends up at this error:

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

This is pretty bizarre, considering I specified "export DYLD_LIBRARY_PATH=/usr/local/mysql/lib" and libmysqlclient.18.dylib is in that path. It seems the linker is looking for libmysqlclient.18.dylib without a path (in the root?). I also ran otool on my php binary and got this:

/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)

Note how libmysqlclient is the only library without a path. Does anyone know how I can solve this? Am I running the configure wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ˇ宁静的妩媚 2024-12-09 08:10:25

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

不过,我在make install过程中确实遇到了后续问题。在安装 PEAR 环境步骤中出现了相同的错误消息。解决这个问题的方法是预先执行此操作:

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

I had a similar problem and I think it was related to the fact that /usr/local/mysql is symlinked to /usr/local/mysql-5.5.15-osx10.6-x86_64 on my computer (MySQL installed via DMG). Changing DYLD_LIBRARY_PATH to use the fully qualified path seemed to get make to work for me.

However, I did encounter a follow-up problem during the make install process. The same error message came up during the Installing PEAR environment step. The solution to that issue was to do this beforehand:

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
清浅ˋ旧时光 2024-12-09 08:10:25

当我尝试在 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. 编译之前,设置路径到数据库lib目录:

    export DYLD_LIBRARY_PATH=/customserver/maria55/lib

  2. 运行 ./compile,并根据需要提供选项

  3. run 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

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

A similar thing happened to me when I tried to compile PHP 5.4.16 together with MariaDB 5.5 on MacOS X 10.6.8 Snow Leopard. During make, the process stopped unexpectedly with this error report:

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

I'm using a whole bunch of non-standard directories for running my server (apache with PHP-CGI), so my configure settings are somewhat odd and unhelpful to others. They have worked for the whole 5.4 branch of PHP with MariaDB 5.2, and only today did it stop working as expected.

Thanks to your postings, this is what I came up with to get it to compile and install successfully again (of course, change paths depending on own requirements):

  1. prior to compile, set the path to the database lib directory:

    export DYLD_LIBRARY_PATH=/customserver/maria55/lib

  2. run ./compile with options as required

  3. run make
  4. run this to fix the broken path to the mysql client library inside both the CGI and CLI binaries:

    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. run sudo make install

Hope this is helpful for other in the same situation

帥小哥 2024-12-09 08:10:25

dns.o 中的第二个 _php_parserr 错误(此处提到此处)也可以通过执行以下操作来解决

Makefile 并将以下标志添加到 EXTRA_LIBS = 部分(除了已有的其他标志之外):

EXTRA_LIBS = -lsresolv

不过,如果您可以通过更改路径来解决它,如上所述,那会更好。

The second _php_parserr in dns.o bug (mentioned here, and here) can also be resolved by doing the following:

Edit your Makefile and add the following flag to the EXTRA_LIBS = section (in addition to the other flags already there):

EXTRA_LIBS = -lsresolv

Though if you can resolve it by changing your paths, as mentioned above, that would be preferable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文