这是我的示例代码:
#include <openssl/asn1.h>
#include <openssl/asn1t.h>
#include <openssl/rsa.h>
#include <openssl/x509.h>
typedef struct key_st {
X509_ALGOR *algorithm_id;
RSA *key_material;
} KEY;
DECLARE_ASN1_FUNCTIONS(KEY)
IMPLEMENT_ASN1_FUNCTIONS(KEY)
int main()
{
return 0;
}
当我编译它时,报告以下错误:
$ gcc -o ssltest ssltest.c -lssl -lcrypto
/tmp/cch0HA77.o: In function `d2i_KEY':
ssltest.c:(.text+0x21): undefined reference to `KEY_it'
/tmp/cch0HA77.o: In function `i2d_KEY':
ssltest.c:(.text+0x48): undefined reference to `KEY_it'
/tmp/cch0HA77.o: In function `KEY_new':
ssltest.c:(.text+0x5e): undefined reference to `KEY_it'
/tmp/cch0HA77.o: In function `KEY_free':
ssltest.c:(.text+0x7a): undefined reference to `KEY_it'
collect2: error: ld returned 1 exit status
检查宏扩展代码后,我发现KEY_it声明为:
extern const ASN1_ITEM KEY_it;
因此,链接器报告未定义的引用。我该如何解决?非常感谢你!
最佳答案
在添加KEY的序列定义后,此问题已解决:
ASN1_SEQUENCE(KEY) = {
ASN1_SIMPLE(KEY, algorithm_id, X509_ALGOR),
ASN1_SIMPLE(KEY, key_material, RSAPublicKey)
} ASN1_SEQUENCE_END(KEY)