在实现rtmp协议时,用到了openssl库,编译时报错,错误如下
In file included from handshake.h:83,
from rtmp.cpp:142:
dh.h: In function ‘DH* DHInit(int)’:
dh.h:214:12: error: invalid use of incomplete type ‘DH’ {aka ‘struct dh_st’}
MP_new(dh->g);
^~
dh.h:129:19: note: in definition of macro ‘MP_new’
#define MP_new(m) m = BN_new()
^
In file included from ../../../../../../Include/openssl/crypto.h:25,
from ../../../../../../Include/openssl/comp.h:16,
from ../../../../../../Include/openssl/ssl.h:17,
from rtmp.cpp:56:
../../../../../../Include/openssl/ossl_typ.h:104:16: note: forward declaration of ‘DH’ {aka ‘struct dh_st’}
typedef struct dh_st DH;
^~~~~
In file included from handshake.h:83,
from rtmp.cpp:142:
dh.h:216:10: error: invalid use of incomplete type ‘DH’ {aka ‘struct dh_st’}
if (!dh->g)
^~
In file included from ../../../../../../Include/openssl/crypto.h:25,
from ../../../../../../Include/openssl/comp.h:16,
from ../../../../../../Include/openssl/ssl.h:17,
from rtmp.cpp:56:
../../../../../../Include/openssl/ossl_typ.h:104:16: note: forward declaration of ‘DH’ {aka ‘struct dh_st’}
typedef struct dh_st DH;
^~~~~
In file included from handshake.h:83,
from rtmp.cpp:142:
dh.h:219:15: error: invalid use of incomplete type ‘DH’ {aka ‘struct dh_st’}
MP_gethex(dh->p, P1024, res); /* prime P1024, see dhgroups.h */
^~
dh.h:137:49: note: in definition of macro ‘MP_gethex’
#define MP_gethex(u, hex, res) res = BN_hex2bn(&u, hex)
^
In file included from ../../../../../../Include/openssl/crypto.h:25,
from ../../../../../../Include/openssl/comp.h:16,
from ../../../../../../Include/openssl/ssl.h:17,
from rtmp.cpp:56:
../../../../../../Include/openssl/ossl_typ.h:104:16: note: forward declaration of ‘DH’ {aka ‘struct dh_st’}
typedef struct dh_st DH;
^~~~~
In file included from handshake.h:83,
from rtmp.cpp:142:
dh.h:225:14: error: invalid use of incomplete type ‘DH’ {aka ‘struct dh_st’}
MP_set_w(dh->g, 2); /* base 2 */
^~
dh.h:130:38: note: in definition of macro ‘MP_set_w’
#define MP_set_w(mpi, w) BN_set_word(mpi, w)
^~~
In file included from ../../../../../../Include/openssl/crypto.h:25,
from ../../../../../../Include/openssl/comp.h:16,
from ../../../../../../Include/openssl/ssl.h:17,
from rtmp.cpp:56:
../../../../../../Include/openssl/ossl_typ.h:104:16: note: forward declaration of ‘DH’ {aka ‘struct dh_st’}
typedef struct dh_st DH;
^~~~~
In file included from handshake.h:83,
from rtmp.cpp:142:
dh.h:227:5: error: invalid use of incomplete type ‘DH’ {aka ‘struct dh_st’}
dh->length = nKeyBits;
^~
In file included from ../../../../../../Include/openssl/crypto.h:25,
from ../../../../../../Include/openssl/comp.h:16,
from ../../../../../../Include/openssl/ssl.h:17,
from rtmp.cpp:56:
../../../../../../Include/openssl/ossl_typ.h:104:16: note: forward declaration of ‘DH’ {aka ‘struct dh_st’}
typedef struct dh_st DH;
^~~~~
In file included from handshake.h:83,
from rtmp.cpp:142:
dh.h: In function ‘int DHGenerateKey(DH*)’:
dh.h:254:32: error: invalid use of incomplete type ‘DH’ {aka ‘struct dh_st’}
res = isValidPublicKey(dh->pub_key, dh->p, q1);
^~
In file included from ../../../../../../Include/openssl/crypto.h:25,
from ../../../../../../Include/openssl/comp.h:16,
from ../../../../../../Include/openssl/ssl.h:17,
from rtmp.cpp:56:
../../../../../../Include/openssl/ossl_typ.h:104:16: note: forward declaration of ‘DH’ {aka ‘struct dh_st’}
typedef struct dh_st DH;
^~~~~
In file included from handshake.h:83,
from rtmp.cpp:142:
dh.h:254:45: error: invalid use of incomplete type ‘DH’ {aka ‘struct dh_st’}
res = isValidPublicKey(dh->pub_key, dh->p, q1);
^~
In file included from ../../../../../../Include/openssl/crypto.h:25,
from ../../../../../../Include/openssl/comp.h:16,
from ../../../../../../Include/openssl/ssl.h:17,
from rtmp.cpp:56:
../../../../../../Include/openssl/ossl_typ.h:104:16: note: forward declaration of ‘DH’ {aka ‘struct dh_st’}
typedef struct dh_st DH;
^~~~~
In file included from handshake.h:83,
from rtmp.cpp:142:
dh.h:257:14: error: invalid use of incomplete type ‘DH’ {aka ‘struct dh_st’}
MP_free(dh->pub_key);
^~
dh.h:136:30: note: in definition of macro ‘MP_free’
#define MP_free(mpi) BN_free(mpi)
^~~
In file included from ../../../../../../Include/openssl/crypto.h:25,
from ../../../../../../Include/openssl/comp.h:16,
from ../../../../../../Include/openssl/ssl.h:17,
from rtmp.cpp:56:
../../../../../../Include/openssl/ossl_typ.h:104:16: note: forward declaration of ‘DH’ {aka ‘struct dh_st’}
typedef struct dh_st DH;
^~~~~
In file included from handshake.h:83,
from rtmp.cpp:142:
dh.h:258:14: error: invalid use of incomplete type ‘DH’ {aka ‘struct dh_st’}
MP_free(dh->priv_key);
^~
dh.h:136:30: note: in definition of macro ‘MP_free’
#define MP_free(mpi) BN_free(mpi)
^~~
In file included from ../../../../../../Include/openssl/crypto.h:25,
from ../../../../../../Include/openssl/comp.h:16,
from ../../../../../../Include/openssl/ssl.h:17,
from rtmp.cpp:56:
../../../../../../Include/openssl/ossl_typ.h:104:16: note: forward declaration of ‘DH’ {aka ‘struct dh_st’}
typedef struct dh_st DH;
^~~~~
In file included from handshake.h:83,
from rtmp.cpp:142:
dh.h:259:6: error: invalid use of incomplete type ‘DH’ {aka ‘struct dh_st’}
dh->pub_key = dh->priv_key = 0;
^~
In file included from ../../../../../../Include/openssl/crypto.h:25,
from ../../../../../../Include/openssl/comp.h:16,
from ../../../../../../Include/openssl/ssl.h:17,
from rtmp.cpp:56:
../../../../../../Include/openssl/ossl_typ.h:104:16: note: forward declaration of ‘DH’ {aka ‘struct dh_st’}
typedef struct dh_st DH;
^~~~~
In file included from handshake.h:83,
from rtmp.cpp:142:
dh.h:259:20: error: invalid use of incomplete type ‘DH’ {aka ‘struct dh_st’}
dh->pub_key = dh->priv_key = 0;
^~
In file included from ../../../../../../Include/openssl/crypto.h:25,
from ../../../../../../Include/openssl/comp.h:16,
from ../../../../../../Include/openssl/ssl.h:17,
from rtmp.cpp:56:
../../../../../../Include/openssl/ossl_typ.h:104:16: note: forward declaration of ‘DH’ {aka ‘struct dh_st’}
typedef struct dh_st DH;
^~~~~
In file included from handshake.h:83,
from rtmp.cpp:142:
dh.h: In function ‘int DHGetPublicKey(DH*, uint8_t*, size_t)’:
dh.h:275:17: error: invalid use of incomplete type ‘DH’ {aka ‘struct dh_st’}
if (!dh || !dh->pub_key)
^~
In file included from ../../../../../../Include/openssl/crypto.h:25,
from ../../../../../../Include/openssl/comp.h:16,
from ../../../../../../Include/openssl/ssl.h:17,
from rtmp.cpp:56:
../../../../../../Include/openssl/ossl_typ.h:104:16: note: forward declaration of ‘DH’ {aka ‘struct dh_st’}
typedef struct dh_st DH;
^~~~~
In file included from ../../../../../../Include/openssl/asn1.h:23,
from ../../../../../../Include/openssl/objects.h:15,
from ../../../../../../Include/openssl/evp.h:28,
from ../../../../../../Include/openssl/x509.h:18,
from ../../../../../../Include/openssl/ssl.h:20,
from rtmp.cpp:56:
dh.h:278:20: error: invalid use of incomplete type ‘DH’ {aka ‘struct dh_st’}
len = MP_bytes(dh->pub_key);
^~
../../../../../../Include/openssl/bn.h:181:40: note: in definition of macro ‘BN_num_bytes’
# define BN_num_bytes(a) ((BN_num_bits(a)+7)/8)
^
dh.h:278:9: note: in expansion of macro ‘MP_bytes’
len = MP_bytes(dh->pub_key);
^~~~~~~~
In file included from ../../../../../../Include/openssl/crypto.h:25,
from ../../../../../../Include/openssl/comp.h:16,
from ../../../../../../Include/openssl/ssl.h:17,
from rtmp.cpp:56:
../../../../../../Include/openssl/ossl_typ.h:104:16: note: forward declaration of ‘DH’ {aka ‘struct dh_st’}
typedef struct dh_st DH;
^~~~~
In file included from handshake.h:83,
from rtmp.cpp:142:
dh.h:283:15: error: invalid use of incomplete type ‘DH’ {aka ‘struct dh_st’}
MP_setbin(dh->pub_key, pubkey + (nPubkeyLen - len), len);
^~
dh.h:139:40: note: in definition of macro ‘MP_setbin’
#define MP_setbin(u,buf,len) BN_bn2bin(u,buf)
^
In file included from ../../../../../../Include/openssl/crypto.h:25,
from ../../../../../../Include/openssl/comp.h:16,
from ../../../../../../Include/openssl/ssl.h:17,
from rtmp.cpp:56:
../../../../../../Include/openssl/ossl_typ.h:104:16: note: forward declaration of ‘DH’ {aka ‘struct dh_st’}
typedef struct dh_st DH;
^~~~~
In file included from handshake.h:83,
from rtmp.cpp:142:
dh.h: In function ‘int DHComputeSharedSecretKey(DH*, uint8_t*, size_t, uint8_t*)’:
dh.h:325:36: error: invalid use of incomplete type ‘DH’ {aka ‘struct dh_st’}
if (isValidPublicKey(pubkeyBn, dh->p, q1))
^~
In file included from ../../../../../../Include/openssl/crypto.h:25,
from ../../../../../../Include/openssl/comp.h:16,
from ../../../../../../Include/openssl/ssl.h:17,
from rtmp.cpp:56:
../../../../../../Include/openssl/ossl_typ.h:104:16: note: forward declaration of ‘DH’ {aka ‘struct dh_st’}
typedef struct dh_st DH;
^~~~~
rtmp.cpp: At global scope:
rtmp.cpp:523:1: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
};
在网上找了好久,最好解决方法如下,修改openssl头文件 dh.h
在
# ifdef __cplusplus
extern "C" {
# endif
和
# ifndef OPENSSL_DH_MAX_MODULUS_BITS
# define OPENSSL_DH_MAX_MODULUS_BITS 10000
# endif
# define OPENSSL_DH_FIPS_MIN_MODULUS_BITS 1024
中间,添加下面代码
struct dh_method {
char *name;
/* Methods here */
int (*generate_key) (DH *dh);
int (*compute_key) (unsigned char *key, const BIGNUM *pub_key, DH *dh);
/* Can be null */
int (*bn_mod_exp) (const DH *dh, BIGNUM *r, const BIGNUM *a,
const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
BN_MONT_CTX *m_ctx);
int (*init) (DH *dh);
int (*finish) (DH *dh);
int flags;
char *app_data;
/* If this is non-NULL, it will be used to generate parameters */
int (*generate_params) (DH *dh, int prime_len, int generator,
BN_GENCB *cb);
};
struct dh_st {
/*
* This first argument is used to pick up errors when a DH is passed
* instead of a EVP_PKEY
*/
int pad;
int version;
BIGNUM *p;
BIGNUM *g;
int32_t length; /* optional */
BIGNUM *pub_key; /* g^x % p */
BIGNUM *priv_key; /* x */
int flags;
BN_MONT_CTX *method_mont_p;
/* Place holders if we want to do X9.42 DH */
BIGNUM *q;
BIGNUM *j;
unsigned char *seed;
int seedlen;
BIGNUM *counter;
int references;
CRYPTO_EX_DATA ex_data;
const DH_METHOD *meth;
ENGINE *engine;
void *lock;
};