2013-01-23 53 views
0

在编译我的源代码我正在以下错误非法重新声明:编译错误:不一致类型声明/对标识符

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 
$ 
+0

'include/smb_ldap.h'文件是否有正确的包含保护? – wildplasser

回答

1

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 
0

作为oleg_g暗示朝向你混合预处理器命令(#定义)和C++的typedef

的预处理器指令( #define等)在解析器处理结果代码之前被处理。当你的typedef ber_tag_t预处理命令永远不会知道这个,而是你需要一个#定义变量来表示类型定义:

#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 

为了澄清;预处理器指令只能看到其他预处理器变量,因为此时尚未解释代码。

编辑: 我还应该提到,如果可能的话,以避免需要的方式布置代码可能是有益的。例如,使用一个单独的公共标题,其中包含和类型受到例如包含警卫的保护。

相关问题