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。



猜你喜欢

转载自blog.csdn.net/ligaofeng/article/details/52674696