未定义的符号_EVP_PKEY_CTX_new_id

Undefined symbols _EVP_PKEY_CTX_new_id

本文关键字:CTX new id PKEY EVP 符号 未定义      更新时间:2023-10-16

我有这个C++代码,它不能在OS X上编译:

#include <iostream>
#include <openssl/evp.h>
int main(int argc,char *argv[]){
        EVP_PKEY_CTX *pctx;
        pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL);
        return 0;
}

在链接我得到这个错误:

Undefined symbols for architecture x86_64:
  "_EVP_PKEY_CTX_new_id", referenced from:
      _main in test-a22ea1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

编译使用:

g++ test.cpp -o test -lssl -lcrypto

OpenSSl-doc说,它应该被定义:https://www.openssl.org/docs/manmaster/crypto/EVP_PKEY_CTX_new.html

这段代码在Linux(Debian 7和OpenSSL 1.0.1e)上运行得很好。但在OS X上不行。有什么建议吗?

我的配置:

  • OS X:10.11.2
  • clang:Apple LLVM版本7.0.2(clang-7001.81)
  • openSSL:openSSL 1.0.2e 2015年12月3日(与Homebrew一起安装)

感谢并祝你新年快乐:)

链接器是否正在获取系统上已安装的sslcrypto库文件的另一个版本?尝试添加-L开关和自制安装文件的路径。