1. 背景
之前建设的跨平台全链路智能语音交互系统一直只跑在Android系统(主要是Iot设备),没有iOS业务场景,最近经过不断的努力,终于要把这个能力推广到B端APP,面向B端用户,这个时候就有了iOS的述求,毕竟从能力建设之初就吹出去了,系统是跨平台的,这个时候不能掉链子。
虽然全链路语音交互SDK已经跑在Andorid、Ubuntu、Mac上跑通,但是在iOS设备上心里还是挺虚。全链路语音交互SDK依赖了curl来直线HTTP2协议的传输,而curl又依赖了nghttp2与openssl,从最底层依赖出发本文先编译openssl库。
2. 编译过程
2.1 寻找工具
作为一个Android开发,对iOS的编译器和平台没有那么熟悉,本来想着直接找现成的工具来编译,github上一搜找到了 github.com/jasonacox/B… 这个工具,它可以运行一个脚本把openssl + nghttp2 + curl 都编出来,一下感觉可以节省很多时间。 这个工具默认支持的版本是:
- OPENSSL : 1.1.1l
- LIBCURL :7.80.0
- NGHTTP2 :1.46.0
全链路语音SDK依赖的版本为:
- OPENSSL : 1.1.0h
- LIBCURL:7.61.0
- NGHTTP2:1.32.0
版本都比工具里面默认的版本低些,为了减少库版本的影响,抱着侥幸心理编译直接替换成自己的版本开始编译,脚本给了警告:
** WARNING: This build script has not been tested with 1.1.0 **
而且最终编译失败了,为了快速验证后面流程,将openssl版本先修改为1.1.1l,结果出奇的顺利,编译过程没有再报任何错,只是整个编译过程花费时间有点长。
有了编译完的静态库,可以开始编译全链路语音交互SDK库了,但是编译到35%,连接静态库时报错了:
[ 35%] Linking CXX shared library libAVSCommon.dylib Undefined symbols for architecture armv7: "_ASN1_STRING_free", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_ASN1_STRING_get0_data", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_ASN1_STRING_length", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_ASN1_STRING_new", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_ASN1_STRING_print", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_ASN1_STRING_to_UTF8", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_ASN1_STRING_type", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_ASN1_TIME_print", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_BIO_ctrl", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) _x509_name_oneline in libcurl.a(libcurl_la-openssl.o) _pubkey_show in libcurl.a(libcurl_la-openssl.o) "_BIO_f_ssl", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_BIO_free", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) _x509_name_oneline in libcurl.a(libcurl_la-openssl.o) "_BIO_new", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) _x509_name_oneline in libcurl.a(libcurl_la-openssl.o) "_BIO_printf", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_BIO_puts", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_BIO_s_file", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_BIO_s_mem", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) _x509_name_oneline in libcurl.a(libcurl_la-openssl.o) "_BN_print", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) _pubkey_show in libcurl.a(libcurl_la-openssl.o) "_CONF_modules_load_file", referenced from: _Curl_ossl_init in libcurl.a(libcurl_la-openssl.o) "_CRYPTO_free", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_CRYPTO_malloc", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_DES_ecb_encrypt", referenced from: _Curl_ntlm_core_lm_resp in libcurl.a(libcurl_la-curl_ntlm_core.o) _Curl_ntlm_core_mk_lm_hash in libcurl.a(libcurl_la-curl_ntlm_core.o) "_DES_set_key", referenced from: _setup_des_key in libcurl.a(libcurl_la-curl_ntlm_core.o) "_DES_set_odd_parity", referenced from: _setup_des_key in libcurl.a(libcurl_la-curl_ntlm_core.o) "_DH_get0_key", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_DH_get0_pqg", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_DSA_get0_key", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_DSA_get0_pqg", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_ENGINE_by_id", referenced from: _Curl_ossl_set_engine in libcurl.a(libcurl_la-openssl.o) "_ENGINE_ctrl", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_ENGINE_ctrl_cmd", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_ENGINE_finish", referenced from: _Curl_ossl_close_all in libcurl.a(libcurl_la-openssl.o) _Curl_ossl_set_engine in libcurl.a(libcurl_la-openssl.o) "_ENGINE_free", referenced from: _Curl_ossl_close_all in libcurl.a(libcurl_la-openssl.o) _Curl_ossl_set_engine in libcurl.a(libcurl_la-openssl.o) "_ENGINE_get_first", referenced from: _Curl_ossl_engines_list in libcurl.a(libcurl_la-openssl.o) "_ENGINE_get_id", referenced from: _Curl_ossl_set_engine_default in libcurl.a(libcurl_la-openssl.o) _Curl_ossl_engines_list in libcurl.a(libcurl_la-openssl.o) "_ENGINE_get_next", referenced from: _Curl_ossl_engines_list in libcurl.a(libcurl_la-openssl.o) "_ENGINE_init", referenced from: _Curl_ossl_set_engine in libcurl.a(libcurl_la-openssl.o) "_ENGINE_load_private_key", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_ENGINE_set_default", referenced from: _Curl_ossl_set_engine_default in libcurl.a(libcurl_la-openssl.o) "_ERR_clear_error", referenced from: _Curl_ossl_shutdown in libcurl.a(libcurl_la-openssl.o) _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) _ossl_recv in libcurl.a(libcurl_la-openssl.o) _ossl_send in libcurl.a(libcurl_la-openssl.o) "_ERR_error_string_n", referenced from: _Curl_ossl_shutdown in libcurl.a(libcurl_la-openssl.o) _Curl_ossl_set_engine in libcurl.a(libcurl_la-openssl.o) _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) _ossl_recv in libcurl.a(libcurl_la-openssl.o) _ossl_send in libcurl.a(libcurl_la-openssl.o) "_ERR_get_error", referenced from: _Curl_ossl_shutdown in libcurl.a(libcurl_la-openssl.o) _Curl_ossl_set_engine in libcurl.a(libcurl_la-openssl.o) _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) _ossl_recv in libcurl.a(libcurl_la-openssl.o) _ossl_send in libcurl.a(libcurl_la-openssl.o) "_ERR_peek_error", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_EVP_DigestFinal_ex", referenced from: _Curl_ossl_md5sum in libcurl.a(libcurl_la-openssl.o) _Curl_ossl_sha256sum in libcurl.a(libcurl_la-openssl.o) "_EVP_DigestInit_ex", referenced from: _Curl_ossl_md5sum in libcurl.a(libcurl_la-openssl.o) _Curl_ossl_sha256sum in libcurl.a(libcurl_la-openssl.o) "_EVP_DigestUpdate", referenced from: _Curl_ossl_md5sum in libcurl.a(libcurl_la-openssl.o) _Curl_ossl_sha256sum in libcurl.a(libcurl_la-openssl.o) "_EVP_MD_CTX_free", referenced from: _Curl_ossl_md5sum in libcurl.a(libcurl_la-openssl.o) _Curl_ossl_sha256sum in libcurl.a(libcurl_la-openssl.o) "_EVP_MD_CTX_new", referenced from: _Curl_ossl_md5sum in libcurl.a(libcurl_la-openssl.o) _Curl_ossl_sha256sum in libcurl.a(libcurl_la-openssl.o) "_EVP_PKEY_copy_parameters", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_EVP_PKEY_free", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_EVP_PKEY_get0_DH", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_EVP_PKEY_get0_DSA", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_EVP_PKEY_get0_RSA", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_EVP_PKEY_get1_RSA", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_EVP_PKEY_id", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_EVP_md5", referenced from: _Curl_ossl_md5sum in libcurl.a(libcurl_la-openssl.o) "_EVP_sha256", referenced from: _Curl_ossl_sha256sum in libcurl.a(libcurl_la-openssl.o) "_GENERAL_NAMES_free", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_MD4_Final", referenced from: _Curl_ntlm_core_mk_nt_hash in libcurl.a(libcurl_la-curl_ntlm_core.o) "_MD4_Init", referenced from: _Curl_ntlm_core_mk_nt_hash in libcurl.a(libcurl_la-curl_ntlm_core.o) "_MD4_Update", referenced from: _Curl_ntlm_core_mk_nt_hash in libcurl.a(libcurl_la-curl_ntlm_core.o) "_MD5_Final", referenced from: _Curl_md5it in libcurl.a(libcurl_la-md5.o) _Curl_HMAC_MD5 in libcurl.a(libcurl_la-md5.o) _Curl_DIGEST_MD5 in libcurl.a(libcurl_la-md5.o) "_MD5_Init", referenced from: _Curl_md5it in libcurl.a(libcurl_la-md5.o) _Curl_HMAC_MD5 in libcurl.a(libcurl_la-md5.o) _Curl_DIGEST_MD5 in libcurl.a(libcurl_la-md5.o) "_MD5_Update", referenced from: _Curl_md5it in libcurl.a(libcurl_la-md5.o) _Curl_HMAC_MD5 in libcurl.a(libcurl_la-md5.o) _Curl_DIGEST_MD5 in libcurl.a(libcurl_la-md5.o) "_OCSP_BASICRESP_free", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_OCSP_RESPONSE_free", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_OCSP_basic_verify", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_OCSP_cert_status_str", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_OCSP_check_validity", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_OCSP_crl_reason_str", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_OCSP_resp_count", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_OCSP_resp_get0", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_OCSP_response_get1_basic", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_OCSP_response_status", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_OCSP_response_status_str", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_OCSP_single_get0_status", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_OPENSSL_load_builtin_modules", referenced from: _Curl_ossl_init in libcurl.a(libcurl_la-openssl.o) "_OPENSSL_sk_num", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_OPENSSL_sk_pop", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_OPENSSL_sk_pop_free", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_OPENSSL_sk_value", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_OpenSSL_version_num", referenced from: _Curl_ossl_version in libcurl.a(libcurl_la-openssl.o) "_PEM_read_bio_X509", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_PEM_write_bio_X509", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_PKCS12_PBE_add", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_PKCS12_free", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_PKCS12_parse", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_RAND_add", referenced from: _Curl_ossl_seed in libcurl.a(libcurl_la-openssl.o) "_RAND_bytes", referenced from: _Curl_ossl_random in libcurl.a(libcurl_la-openssl.o) "_RAND_file_name", referenced from: _Curl_ossl_seed in libcurl.a(libcurl_la-openssl.o) "_RAND_load_file", referenced from: _Curl_ossl_seed in libcurl.a(libcurl_la-openssl.o) "_RAND_status", referenced from: _Curl_ossl_random in libcurl.a(libcurl_la-openssl.o) _Curl_ossl_seed in libcurl.a(libcurl_la-openssl.o) "_RSA_flags", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_RSA_free", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_RSA_get0_key", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SHA256_Final", referenced from: _Curl_sha256it in libcurl.a(libcurl_la-sha256.o) "_SHA256_Init", referenced from: _Curl_sha256it in libcurl.a(libcurl_la-sha256.o) "_SHA256_Update", referenced from: _Curl_sha256it in libcurl.a(libcurl_la-sha256.o) "_SSL_CIPHER_get_name", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_add_client_CA", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_check_private_key", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_ctrl", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_free", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) _ossl_close in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_get_cert_store", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_load_verify_locations", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_new", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_set_alpn_protos", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_set_cipher_list", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_set_default_passwd_cb", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_set_default_passwd_cb_userdata", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_set_msg_callback", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_set_next_proto_select_cb", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_set_options", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_set_srp_password", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_set_srp_username", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_set_verify", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_use_PrivateKey", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_use_PrivateKey_file", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_use_certificate", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_use_certificate_chain_file", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_CTX_use_certificate_file", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_SESSION_free", referenced from: _Curl_ossl_session_free in libcurl.a(libcurl_la-openssl.o) _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_SESSION_get_master_key", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_connect", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_ctrl", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_free", referenced from: _Curl_ossl_shutdown in libcurl.a(libcurl_la-openssl.o) _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) _ossl_close in libcurl.a(libcurl_la-openssl.o) "_SSL_get0_alpn_selected", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_get1_session", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_get_certificate", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_get_client_random", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_get_current_cipher", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_get_error", referenced from: _Curl_ossl_shutdown in libcurl.a(libcurl_la-openssl.o) _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) _ossl_recv in libcurl.a(libcurl_la-openssl.o) _ossl_send in libcurl.a(libcurl_la-openssl.o) "_SSL_get_peer_cert_chain", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_get_peer_certificate", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_get_privatekey", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_get_session", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_get_shutdown", referenced from: _Curl_ossl_shutdown in libcurl.a(libcurl_la-openssl.o) "_SSL_get_verify_result", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_new", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_pending", referenced from: _Curl_ossl_data_pending in libcurl.a(libcurl_la-openssl.o) "_SSL_read", referenced from: _Curl_ossl_shutdown in libcurl.a(libcurl_la-openssl.o) _ossl_recv in libcurl.a(libcurl_la-openssl.o) "_SSL_set_bio", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_set_connect_state", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) _ossl_close in libcurl.a(libcurl_la-openssl.o) "_SSL_set_fd", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_set_session", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_shutdown", referenced from: _Curl_ossl_shutdown in libcurl.a(libcurl_la-openssl.o) _ossl_close in libcurl.a(libcurl_la-openssl.o) "_SSL_version", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_SSL_write", referenced from: _ossl_send in libcurl.a(libcurl_la-openssl.o) "_TLS_client_method", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_UI_OpenSSL", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) _ssl_ui_reader in libcurl.a(libcurl_la-openssl.o) _ssl_ui_writer in libcurl.a(libcurl_la-openssl.o) "_UI_create_method", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_UI_destroy_method", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_UI_get0_user_data", referenced from: _ssl_ui_reader in libcurl.a(libcurl_la-openssl.o) _ssl_ui_writer in libcurl.a(libcurl_la-openssl.o) "_UI_get_input_flags", referenced from: _ssl_ui_reader in libcurl.a(libcurl_la-openssl.o) _ssl_ui_writer in libcurl.a(libcurl_la-openssl.o) "_UI_get_string_type", referenced from: _ssl_ui_reader in libcurl.a(libcurl_la-openssl.o) _ssl_ui_writer in libcurl.a(libcurl_la-openssl.o) "_UI_method_get_closer", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_UI_method_get_opener", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_UI_method_get_reader", referenced from: _ssl_ui_reader in libcurl.a(libcurl_la-openssl.o) "_UI_method_get_writer", referenced from: _ssl_ui_writer in libcurl.a(libcurl_la-openssl.o) "_UI_method_set_closer", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_UI_method_set_opener", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_UI_method_set_reader", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_UI_method_set_writer", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_UI_set_result", referenced from: _ssl_ui_reader in libcurl.a(libcurl_la-openssl.o) "_X509V3_EXT_print", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_EXTENSION_get_data", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_EXTENSION_get_object", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_LOOKUP_file", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_NAME_ENTRY_get_data", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_NAME_get_entry", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_NAME_get_index_by_NID", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_NAME_print_ex", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) _x509_name_oneline in libcurl.a(libcurl_la-openssl.o) "_X509_STORE_add_lookup", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_STORE_set_flags", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_check_issued", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_free", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_get0_extensions", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_get0_notAfter", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_get0_notBefore", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_get0_signature", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_get_X509_PUBKEY", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_get_ext_d2i", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_get_issuer_name", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_get_pubkey", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_get_serialNumber", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_get_subject_name", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_get_version", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_load_crl_file", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_signature_print", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_X509_verify_cert_error_string", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_d2i_OCSP_RESPONSE", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_d2i_PKCS12_bio", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_i2a_ASN1_OBJECT", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_i2d_X509_PUBKEY", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_i2t_ASN1_OBJECT", referenced from: _ossl_connect_common in libcurl.a(libcurl_la-openssl.o) "_inflate", referenced from: _inflate_stream in libcurl.a(libcurl_la-content_encoding.o) "_inflateEnd", referenced from: _inflate_stream in libcurl.a(libcurl_la-content_encoding.o) _exit_zlib in libcurl.a(libcurl_la-content_encoding.o) "_inflateInit2_", referenced from: _inflate_stream in libcurl.a(libcurl_la-content_encoding.o) _gzip_init_writer in libcurl.a(libcurl_la-content_encoding.o) "_inflateInit_", referenced from: _deflate_init_writer in libcurl.a(libcurl_la-content_encoding.o) "_nghttp2_http2_strerror", referenced from: _Curl_http2_strerror in libcurl.a(libcurl_la-http2.o) _http2_handle_stream_close in libcurl.a(libcurl_la-http2.o) "_nghttp2_is_fatal", referenced from: _on_frame_recv in libcurl.a(libcurl_la-http2.o) _Curl_http2_switched in libcurl.a(libcurl_la-http2.o) _http2_recv in libcurl.a(libcurl_la-http2.o) _http2_send in libcurl.a(libcurl_la-http2.o) "_nghttp2_pack_settings_payload", referenced from: _Curl_http2_request_upgrade in libcurl.a(libcurl_la-http2.o) "_nghttp2_priority_spec_init", referenced from: _h2_pri_spec in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_callbacks_del", referenced from: _Curl_http2_init in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_callbacks_new", referenced from: _Curl_http2_init in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_callbacks_set_before_frame_send_callback", referenced from: _Curl_http2_init in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_callbacks_set_error_callback", referenced from: _Curl_http2_init in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_callbacks_set_on_begin_headers_callback", referenced from: _Curl_http2_init in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_callbacks_set_on_data_chunk_recv_callback", referenced from: _Curl_http2_init in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_callbacks_set_on_frame_not_send_callback", referenced from: _Curl_http2_init in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_callbacks_set_on_frame_recv_callback", referenced from: _Curl_http2_init in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_callbacks_set_on_frame_send_callback", referenced from: _Curl_http2_init in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_callbacks_set_on_header_callback", referenced from: _Curl_http2_init in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_callbacks_set_on_invalid_frame_recv_callback", referenced from: _Curl_http2_init in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_callbacks_set_on_stream_close_callback", referenced from: _Curl_http2_init in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_callbacks_set_send_callback", referenced from: _Curl_http2_init in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_client_new", referenced from: _Curl_http2_init in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_del", referenced from: _http2_disconnect in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_get_remote_settings", referenced from: _on_frame_recv in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_get_stream_user_data", referenced from: _on_frame_recv in libcurl.a(libcurl_la-http2.o) _on_invalid_frame_recv in libcurl.a(libcurl_la-http2.o) _on_data_chunk_recv in libcurl.a(libcurl_la-http2.o) _before_frame_send in libcurl.a(libcurl_la-http2.o) _on_frame_send in libcurl.a(libcurl_la-http2.o) _on_frame_not_send in libcurl.a(libcurl_la-http2.o) _on_stream_close in libcurl.a(libcurl_la-http2.o) ... "_nghttp2_session_mem_recv", referenced from: _h2_process_pending_input in libcurl.a(libcurl_la-http2.o) _Curl_http2_switched in libcurl.a(libcurl_la-http2.o) _http2_recv in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_resume_data", referenced from: _Curl_http2_done_sending in libcurl.a(libcurl_la-http2.o) _http2_send in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_send", referenced from: _http2_send in libcurl.a(libcurl_la-http2.o) _h2_session_send in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_set_local_window_size", referenced from: _Curl_http2_switched in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_set_stream_user_data", referenced from: _Curl_http2_done in libcurl.a(libcurl_la-http2.o) _on_frame_recv in libcurl.a(libcurl_la-http2.o) _on_stream_close in libcurl.a(libcurl_la-http2.o) _Curl_http2_switched in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_upgrade", referenced from: _Curl_http2_switched in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_want_read", referenced from: _should_close_session in libcurl.a(libcurl_la-http2.o) "_nghttp2_session_want_write", referenced from: _should_close_session in libcurl.a(libcurl_la-http2.o) _http2_getsock in libcurl.a(libcurl_la-http2.o) _http2_perform_getsock in libcurl.a(libcurl_la-http2.o) "_nghttp2_strerror", referenced from: _h2_process_pending_input in libcurl.a(libcurl_la-http2.o) _Curl_http2_switched in libcurl.a(libcurl_la-http2.o) _http2_recv in libcurl.a(libcurl_la-http2.o) "_nghttp2_submit_priority", referenced from: _h2_session_send in libcurl.a(libcurl_la-http2.o) "_nghttp2_submit_request", referenced from: _http2_send in libcurl.a(libcurl_la-http2.o) "_nghttp2_submit_rst_stream", referenced from: _Curl_http2_done in libcurl.a(libcurl_la-http2.o) _on_frame_recv in libcurl.a(libcurl_la-http2.o) "_nghttp2_submit_settings", referenced from: _Curl_http2_switched in libcurl.a(libcurl_la-http2.o) "_nghttp2_version", referenced from: _Curl_http2_ver in libcurl.a(libcurl_la-http2.o) "_zlibVersion", referenced from: _curl_version in libcurl.a(libcurl_la-version.o) _curl_version_info in libcurl.a(libcurl_la-version.o) _gzip_init_writer in libcurl.a(libcurl_la-content_encoding.o) ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)
编译完的curl库中找不到我们依赖的openssl方法,在openssl 1.1.1l中果然搜不到这些方法,没办法,还得改回1.1.0h。
2.2 openssl configure配置脚本
现成的工具用不了了,只好自己去研究openssl的编译文档,找到了官网文档:wiki.openssl.org/index.php/C…
2.2.1 32-bit
OpenSSL 1.1.0及以上版本,32-bit iOS 跨平台编译器 uses the ios-cross
作为目标:
$ export CC=clang; $ export CROSS_TOP=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer $ export CROSS_SDK=iPhoneOS.sdk $ export PATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:$PATH" $ ./Configure ios-cross no-shared no-dso no-hw no-engine --prefix=/usr/local/openssl-ios Configuring OpenSSL version 1.1.1-dev (0x10101000L) no-afalgeng [forced] OPENSSL_NO_AFALGENG no-asan [default] OPENSSL_NO_ASAN no-dso [option] no-dynamic-engine [forced] ... no-weak-ssl-ciphers [default] OPENSSL_NO_WEAK_SSL_CIPHERS no-zlib [default] no-zlib-dynamic [default] Configuring for ios-cross PERL =perl PERLVERSION =5.16.2 for darwin-thread-multi-2level HASHBANGPERL =/usr/bin/env perl CC =clang CFLAG =-O3 -D_REENTRANT -arch armv7 -mios-version-min=6.0.0 -isysroot $(CROSS_TOP)/SDKs/$(CROSS_SDK) -fno-common CXX =c++ CXXFLAG =-O3 -D_REENTRANT -arch armv7 -mios-version-min=6.0.0 -isysroot $(CROSS_TOP)/SDKs/$(CROSS_SDK) -fno-common DEFINES =NDEBUG OPENSSL_THREADS OPENSSL_NO_DYNAMIC_ENGINE OPENSSL_PIC OPENSSL_BN_ASM_MONT OPENSSL_BN_ASM_GF2m SHA1_ASM SHA256_ASM SHA512_ASM AES_ASM BSAES_ASM GHASH_ASM ECP_NISTZ256_ASM POLY1305_ASM ...
OpenSSL 1.0.2及以下,使用iphoneos-cross作为目标:
$ export CC=clang; $ export CROSS_TOP=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer $ export CROSS_SDK=iPhoneOS.sdk $ export PATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:$PATH" $ ./Configure iphoneos-cross no-shared no-dso no-hw no-engine --prefix=/usr/local/openssl-ios Configuring for iphoneos-cross no-dso [option] no-engine [option] OPENSSL_NO_ENGINE (skip dir) no-gmp [default] OPENSSL_NO_GMP (skip dir) no-hw [option] OPENSSL_NO_HW ... no-weak-ssl-ciphers [default] OPENSSL_NO_WEAK_SSL_CIPHERS (skip dir) no-zlib [default] no-zlib-dynamic [default] IsMK1MF=0 CC =clang CFLAG =-DOPENSSL_THREADS -D_REENTRANT -O3 -isysroot $(CROSS_TOP)/SDKs/$(CROSS_SDK) -fomit-frame-pointer -fno-common ...
2.2.2 64bit
OpenSSL 1.1.0及以上版本跨平台编译器使用ios64-cross作为目标:
$ export CC=clang; $ export CROSS_TOP=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer $ export CROSS_SDK=iPhoneOS.sdk $ export PATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:$PATH" $ ./Configure ios64-cross no-shared no-dso no-hw no-engine --prefix=/usr/local/openssl-ios64 Configuring OpenSSL version 1.1.1-dev (0x10101000L) no-afalgeng [forced] OPENSSL_NO_AFALGENG no-asan [default] OPENSSL_NO_ASAN no-dso [option] no-dynamic-engine [forced] ... no-weak-ssl-ciphers [default] OPENSSL_NO_WEAK_SSL_CIPHERS no-zlib [default] no-zlib-dynamic [default] Configuring for ios64-cross PERL =perl PERLVERSION =5.16.2 for darwin-thread-multi-2level HASHBANGPERL =/usr/bin/env perl CC =clang CFLAG =-O3 -D_REENTRANT -arch arm64 -mios-version-min=7.0.0 -isysroot $(CROSS_TOP)/SDKs/$(CROSS_SDK) -fno-common CXX =c++ CXXFLAG =-O3 -D_REENTRANT -arch arm64 -mios-version-min=7.0.0 -isysroot $(CROSS_TOP)/SDKs/$(CROSS_SDK) -fno-common DEFINES =NDEBUG OPENSSL_THREADS OPENSSL_NO_DYNAMIC_ENGINE OPENSSL_PIC OPENSSL_BN_ASM_MONT SHA1_ASM SHA256_ASM SHA512_ASM VPAES_ASM ECP_NISTZ256_ASM POLY1305_ASM ...
1.0.2及以下版本不支持64位。
2.3 target说明
像 ios64-cross 和 ios-cross 这些taget是在哪定义使用呢? 以1.1.0h为例,在源码中Configurations下可以看到:
10-main.conf 50-djgpp.conf 50-haiku.conf 50-masm.conf 90-team.conf INTERNALS.Configure README
几个conf文件,我们可以在10-main.conf中看到这些target的定义:
"iphoneos-cross" => { inherit_from => [ "darwin-common" ], cflags => add("-isysroot \$(CROSS_TOP)/SDKs/\$(CROSS_SDK) -fno-common"), sys_id => "iOS", }, "ios-cross" => { inherit_from => [ "darwin-common", asm("armv4_asm") ], # It should be possible to go below iOS 6 and even add -arch armv6, # thus targeting iPhone pre-3GS, but it's assumed to be irrelevant # at this point. cflags => add("-arch armv7 -mios-version-min=6.0.0 -isysroot \$(CROSS_TOP)/SDKs/\$(CROSS_SDK) -fno-common"), sys_id => "iOS", perlasm_scheme => "ios32", }, "ios64-cross" => { inherit_from => [ "darwin-common", asm("aarch64_asm") ], cflags => add("-arch arm64 -mios-version-min=7.0.0 -isysroot \$(CROSS_TOP)/SDKs/\$(CROSS_SDK) -fno-common"), sys_id => "iOS", bn_ops => "SIXTY_FOUR_BIT_LONG RC4_CHAR", perlasm_scheme => "ios64", },
其他具体参数配置可以参考Configurations下的README,根据说明我们可以找到对应的各种配置参数说明。
2.4 合并静态库
通过一系列修改终于成功编译除了openssl静态库,iOS 设备的CPU架构有两种模拟器和真机 在模拟器上支持:
- iPhone4s-5: i386 架构
- iPhone5s-8 Plus: x86_64 架构
在真机设备上支持:
- armv6: iPhone、iPhone 2、iPhone 3G、iPod Touch(第一代)、iPod Touch(第二代)
- armv7: iPhone 3Gs、iPhone 4、iPhone 4s、iPad、iPad 2
- armv7s: iPhone 5、iPhone 5c (静态库只要支持了armv7,就可以在armv7s的架构上运行)
- arm64: iPhone 5s、iPhone 6、iPhone 6 Plus、iPhone 6s、iPhone 6s Plus、iPad Air、iPad Air2、iPad mini2、iPad mini3
我们要将多个架构库合并成一个,这时又出错了:
have the same architectures (x86_64) and can't be in the same fat output file
先去了解一下lipo用法:
lipo是管理Fat File的工具, 可以查看cpu架构, 提取特定架构,整合和拆分库文件。
- lipo -info xxxx.framework/xxxx或/xxxx.a 查看信息,支持的cpu架构列表
- lipo -create xxxx xxxx -output xxx 整合成Fat文件
- lipo xxxx -thin cpu(armv7/arm64等) -output xxx 提取特定的cpu架构的thin文件
- lipo -remove cpu(armv7/arm64等) xxxx -output xxxx 移除掉特定的cpu架构的文件
通过lipo看到x86_64和arm64是一样的架构,还是编译配置有问题,修改target后终于成功编出来了,而且后面的nghttp2 和 libcurl也很顺利的编译出来了。
2.5 动态库静态库混乱
成功编译出libcur后终于可以编译自己的代码了,但是一运行脚本啥样了,还是前面一样的错,各种Undefined symbols错误。一下没有思路了,最后去找iOS同学探讨了一波,最后才想起来,自己项目的cmake脚本中配置的编译产物都是动态库,而iOS是需要静态库,动态库依赖静态库就会有问题,最后终于在修改了几十个CMakeLists.txt后终于编译出了最终的产物。
3. 总结
一方面没有仔细了解openssl的Configurations配置规则,碰运气似的尝试以及后面学习这些规划花费了些时间;二是动态库引用静态库导致的问题自己误以为是版本不匹配问题浪费了很多时间。