ASN.1结构迭代器只是声明但未实现

时间:2017-08-28 06:26:07

标签: ssl hyperlink openssl asn.1

这是我的示例代码:

#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;

因此链接器报告未定义的引用。我该如何解决?非常感谢你!

1 个答案:

答案 0 :(得分:0)

在我添加KEY的序列定义后修复了它:

ASN1_SEQUENCE(KEY) = { 
    ASN1_SIMPLE(KEY, algorithm_id, X509_ALGOR), 
    ASN1_SIMPLE(KEY, key_material, RSAPublicKey) 
} ASN1_SEQUENCE_END(KEY)