mac下编译安装php7时报ld: symbol(s) not found for architecture x86_64的解决方法

在Mac上编译PHP7时,如果使用OpenSSL扩展,会有一个错误

Undefined symbols for architecture x86_64:
  "_PKCS5_PBKDF2_HMAC", referenced from:
      _zif_openssl_pbkdf2 in openssl.o
  "_SSL_CTX_set_alpn_protos", referenced from:
      _php_openssl_setup_crypto in xp_ssl.o
  "_SSL_CTX_set_alpn_select_cb", referenced from:
      _php_openssl_setup_crypto in xp_ssl.o
  "_SSL_get0_alpn_selected", referenced from:
      _php_openssl_sockop_set_option in xp_ssl.o
  "_SSL_select_next_proto", referenced from:
      _server_alpn_callback in xp_ssl.o
  "_TLSv1_1_client_method", referenced from:
      _php_openssl_setup_crypto in xp_ssl.o
  "_TLSv1_1_server_method", referenced from:
      _php_openssl_setup_crypto in xp_ssl.o
  "_TLSv1_2_client_method", referenced from:
      _php_openssl_setup_crypto in xp_ssl.o
  "_TLSv1_2_server_method", referenced from:
      _php_openssl_setup_crypto in xp_ssl.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


这个问题困扰了我好大一会,最后参考https://blog.51php.org/mac-e7-bc-96-e8-af-91php7-e6-97-b6-e5-bc-95-e5-85-a5openssl-e6-97-b6-e7-9a-84-e9-94-99-e8-af-afundefined-symbols-for-architecture-x86_64/上的方法给解决了,在此转载记录下


这个错误其实很好解决,打开php7源码根目录,打开Makefile文件,大概在110行左右EXTRA_LIBS = 这句话这里,这个地方不能用系统生成的-lcrypto和-lssl,把这两句替换成

/usr/local/Cellar/openssl/1.0.2c/lib/libcrypto.dylib /usr/local/Cellar/openssl/1.0.2c/lib/libssl.dylib

这两个文件在使用brew安装openssl后会出现在这个目录中,当然你也可以自己编译OpenSSL这样再重新make就不会提示这个错误了,当然如果其他扩展出现这个问题也可以用这个方法解决,比如iconv,就把-liconv替换成/usr/local/Cellar/libiconv/1.14/lib/libiconv.dylib。



  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值