簡體   English   中英

運行時出錯。 類型沖突和先前的聲明

[英]error while make runs. Conflicting types and previous declaration

我找到了我正在做的項目的AES實現。

但是,當我集成它時,在構建過程中出現以下錯誤。

In file included from ff.h:26:0,
             from disp.h:4,
             from main.c:14:
aes.h:14:3: error: conflicting types for 'AesCtx'
aes.h:14:3: note: previous declaration of 'AesCtx' was here
aes.h:28:5: error: conflicting types for 'AesCtxIni'
aes.h:28:5: note: previous declaration of 'AesCtxIni' was here
aes.h:29:5: error: conflicting types for 'AesEncrypt'
aes.h:29:5: note: previous declaration of 'AesEncrypt' was here
aes.h:30:5: error: conflicting types for 'AesDecrypt'
aes.h:30:5: note: previous declaration of 'AesDecrypt' was here

頭文件本身是:

// AES context structure
typedef struct {
 unsigned int Ek[60];
 unsigned int Dk[60];
 unsigned int Iv[4];
 unsigned char Nr;
 unsigned char Mode;
} AesCtx;

// key length in bytes
#define KEY128 16
#define KEY192 24
#define KEY256 32
// block size in bytes
#define BLOCKSZ 16
// mode
#define EBC 0
#define CBC 1

// AES API function prototype

int AesCtxIni(AesCtx *pCtx, unsigned char *pIV, unsigned char *pKey, unsigned int KeyLen, unsigned char Mode);
int AesEncrypt(AesCtx *pCtx, unsigned char *pData, unsigned char *pCipher, unsigned int DataLen);
int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsigned int CipherLen);

然后使用相應的C文件。

int AesCtxIni(AesCtx *pCtx, unsigned char *pIV, unsigned char *pKey, unsigned int KeyLen, unsigned char Mode)
{
    // Cut out code for brevity
}

int AesEncrypt(AesCtx *pCtx, unsigned char *pData, unsigned char *pCipher, unsigned int DataLen)
{
    // Cut out code for brevity
}

int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsigned int CipherLen)
{
    // Cut out code for brevity
}

我知道這些錯誤通常是由於尚未預先聲明函數或與聲明稍有不同而發生的,但是我看不出有什么區別。

有任何想法嗎?

您正在使用什么編譯器? 我最好的猜測是它試圖說aes.h#include d兩次。 嘗試在aes.h的開頭和結尾添加頭文件保護:

#ifndef AES_H_
#define AES_H_

typedef struct {
...
int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsigned int CipherLen);

#endif /* !AES_H_ */

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM