Mac Intel平台用kerl安装Erlang R25.3编译失败求助
问题
使用kerl安装Erlang R25.3时编译失败,环境信息:
- macOS版本:13.4(22F66),Intel芯片
- clang版本:Apple clang 14.0.3(clang-1403.0.22.14.1)
编译时出现以下错误:
CC ../priv/obj/x86_64-apple-darwin22.5.0/cmac.o CC ../priv/obj/x86_64-apple-darwin22.5.0/common.o CC ../priv/obj/x86_64-apple-darwin22.5.0/dh.o dh.c:93:63: warning: incompatible pointer types passing 'unsigned long *' to parameter of type 'uint64_t *' (aka 'unsigned long long *') [-Wincompatible-pointer-types] params[i++] = OSSL_PARAM_construct_uint64("priv_len", &len); ^~~~ /usr/local/openssl/include/openssl/params.h:77:67: note: passing argument to parameter 'buf' here OSSL_PARAM OSSL_PARAM_construct_uint64(const char *key, uint64_t *buf); ^ dh.c:98:12: error: call to undeclared function 'EVP_PKEY_CTX_new_from_name'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] pctx = EVP_PKEY_CTX_new_from_name(NULL, "DH", NULL); ^ dh.c:98:12: note: did you mean 'EVP_PKEY_CTX_new_provided'? /usr/local/openssl/include/openssl/evp.h:1469:15: note: 'EVP_PKEY_CTX_new_provided' declared here EVP_PKEY_CTX *EVP_PKEY_CTX_new_provided(OPENSSL_CTX *libctx, ^ dh.c:98:10: warning: incompatible integer to pointer conversion assigning to 'EVP_PKEY_CTX *' (aka 'struct evp_pkey_ctx_st *') from 'int' [-Wint-conversion] pctx = EVP_PKEY_CTX_new_from_name(NULL, "DH", NULL); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dh.c:100:9: error: call to undeclared function 'EVP_PKEY_fromdata_init'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] if (EVP_PKEY_fromdata_init(pctx) <= 0) { ^ dh.c:100:9: note: did you mean 'EVP_PKEY_key_fromdata_init'? /usr/local/openssl/include/openssl/evp.h:1562:5: note: 'EVP_PKEY_key_fromdata_init' declared here int EVP_PKEY_key_fromdata_init(EVP_PKEY_CTX *ctx); ^ dh.c:104:40: error: use of undeclared identifier 'EVP_PKEY_KEYPAIR' if (EVP_PKEY_fromdata(pctx, &pkey, EVP_PKEY_KEYPAIR, params) <= 0) { ^ dh.c:111:16: error: call to undeclared function 'EVP_PKEY_CTX_new_from_pkey'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] pctx_gen = EVP_PKEY_CTX_new_from_pkey(NULL, pkey, NULL); ^ dh.c:111:14: warning: incompatible integer to pointer conversion assigning to 'EVP_PKEY_CTX *' (aka 'struct evp_pkey_ctx_st *') from 'int' [-Wint-conversion] pctx_gen = EVP_PKEY_CTX_new_from_pkey(NULL, pkey, NULL); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dh.c:123:10: error: call to undeclared function 'EVP_PKEY_generate'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] if (!EVP_PKEY_generate(pctx_gen, &pkey_gen)) { ^ dh.c:130:10: error: call to undeclared function 'EVP_PKEY_get_bn_param'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] if (!EVP_PKEY_get_bn_param(pkey_gen, "pub", &pub_key_gen)) { ^ dh.c:206:17: error: call to undeclared function 'EVP_PKEY_CTX_new_from_name'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] peer_pctx = EVP_PKEY_CTX_new_from_name(NULL, "DH", NULL); ^ dh.c:206:15: warning: incompatible integer to pointer conversion assigning to 'EVP_PKEY_CTX *' (aka 'struct evp_pkey_ctx_st *') from 'int' [-Wint-conversion] peer_pctx = EVP_PKEY_CTX_new_from_name(NULL, "DH", NULL); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dh.c:208:9: error: call to undeclared function 'EVP_PKEY_fromdata_init'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] if (EVP_PKEY_fromdata_init(peer_pctx) <= 0) ^ dh.c:210:50: error: use of undeclared identifier 'EVP_PKEY_KEYPAIR' if (EVP_PKEY_fromdata(peer_pctx, &peer_pkey, EVP_PKEY_KEYPAIR, params) <= 0) ^ dh.c:217:14: warning: incompatible integer to pointer conversion assigning to 'EVP_PKEY_CTX *' (aka 'struct evp_pkey_ctx_st *') from 'int' [-Wint-conversion] own_pctx = EVP_PKEY_CTX_new_from_name(NULL, "DH", NULL); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dh.c:222:48: error: use of undeclared identifier 'EVP_PKEY_KEYPAIR' if (EVP_PKEY_fromdata(own_pctx, &own_pkey, EVP_PKEY_KEYPAIR, params) <= 0) ^ 5 warnings and 10 errors generated.
疑问:这是否是clang版本与Erlang R25.3冲突导致的?该如何解决此问题?
解答
不是clang版本的问题,核心原因是Erlang R25.3依赖OpenSSL 1.1.x版本,但当前使用的是OpenSSL 3.x版本。错误里的EVP_PKEY_CTX_new_from_name等函数是OpenSSL 3.x新增的API,而Erlang R25.3的代码是针对OpenSSL 1.1.x编写的,因此会出现函数未声明的错误。
解决步骤:
- 安装OpenSSL 1.1.x版本
- 用Homebrew安装:
brew install openssl@1.1
- 用Homebrew安装:
- 在kerl编译时指定OpenSSL 1.1.x的路径
- 先获取OpenSSL 1.1的安装路径:
brew --prefix openssl@1.1,会输出类似/usr/local/opt/openssl@1.1的路径 - 使用kerl编译时设置环境变量:
KERL_CONFIGURE_OPTIONS="--with-ssl=$(brew --prefix openssl@1.1)" kerl build R25.3 R25.3
- 先获取OpenSSL 1.1的安装路径:
- 编译完成后,安装该版本:
kerl install R25.3 ~/erlang/r25.3 - 激活环境:
. ~/erlang/r25.3/activate
如果之前已经用kerl下载过源码,先清理旧的编译缓存:kerl clean R25.3,再重新执行编译步骤。
内容的提问来源于stack exchange,提问作者俞钦峰
相关产品推荐
相关产品推荐

