簡體   English   中英

C中的編譯錯誤:不一致的類型聲明/標識符的非法重新聲明

[英]Compilation error in C: Inconsistent type declaration/Illegal redeclaration for identifier

編譯源代碼時出現以下錯誤:

Compiling lib/netapi/joindomain.c
cc: "include/smb_ldap.h", line 33: error 1584: Inconsistent type declaration: "ber_tag_t".
cc: "include/smb_ldap.h", line 34: error 1713: Illegal redeclaration for identifier "ber_int_t".
The following command failed:
)
*** Error exit code 1

標記該錯誤的相應代碼是:

if HAVE_LBER_H
#include <lber.h>
#if defined(HPUX) && !defined(_LBER_TYPES_H)
#ifndef ber_tag_t
typedef unsigned long ber_tag_t;
typedef int ber_int_t;
#endif
#endif 

我需要幫助來了解此錯誤的根本原因。

提前致謝。

這是我的機器和編譯器的詳細信息,以供參考:

$  uname -a
HP-UX cifsvade B.11.31 U 9000/800 3751280844 unlimited-user license
$  which cc
/usr/bin/cc
$  ls -lrt /usr/bin/cc
lrwxr-xr-x   1 root       sys             17 Oct  8 17:45 /usr/bin/cc -> /opt/ansic/bin/cc
$ 

lber.h定義ber_tag_t和ber_tag_t如下:

    typedef impl_tag_t ber_tag_t;
    typedef impl_int_t ber_int_t;

在您的代碼中,您嘗試重新定義它們,情況就是這樣。 一個條件

    #ifndef ber_tag_t

除非您在ber_tag_t定義類似

    #define ber_tag_t smth

就像oleg_g提示您混合使用預處理程序命令(#define)和c ++ typedef

在解析器處理結果代碼之前,先處理預處理程序指令(#define等)。 當您鍵入def ber_tag_t時,預處理器命令將永遠不會知道這一點,而是需要#define一個變量以指示已定義類型。

#if HAVE_LBER_H
#include <lber.h>
#if defined(HPUX) && !defined(_LBER_TYPES_H)
#ifndef DEFINED_BER_TAG_T
#define DEFINED_BER_TAG_T
typedef unsigned long ber_tag_t;
typedef int ber_int_t;
#endif
#endif 

澄清; preprocessor指令只能看到其他預處理器變量,因為此時您的代碼尚未被解釋。

編輯:我還應該提到,如果可能的話,以一種避免這種需要的方式來布置代碼可能會有所幫助。 例如,使用單獨的公共標頭,其中包含和類型由例如包含保護保護。

暫無
暫無

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

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