【发布时间】:2015-12-31 17:17:34
【问题描述】:
我有这个不能在 OS X 上编译的 C++ 代码:
#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 with OpenSSL 1.0.1e)上完美运行。但不是在 OS X 上。有什么建议吗?
我的配置:
- OS X:10.11.2
- clang:Apple LLVM 版本 7.0.2 (clang-700.1.81)
- openSSL:OpenSSL 1.0.2e 2015 年 12 月 3 日(随 Homebrew 安装)
感谢新年快乐:)
【问题讨论】:
-
C 不是 C++ 不是 C!
-
如果您想查看在 OpenSSL 中实际使用某些 C++ 功能的示例,请查看How to generate RSA private key using openssl 和Using openssl to generate a DSA key pair。答案使用
unique_ptr自动释放使用OpenSSL 的*_new函数获取的资源,例如RSA_new和DSA_new。