Mac编译PHP7时引入OpenSSL时的错误Undefined symbols for architecture x86_64

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

1
2
3
4
Undefined symbols for architecture x86_64:
"_PKCS5_PBKDF2_HMAC", referenced from:
_zif_openssl_pbkdf2 in openssl.o
"_SSL_CTX_set_alpn_protos", referenced from:

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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)

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

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

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