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
$ 
4

2 回答 2

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
于 2013-01-23T13:36:25.033 回答
0

正如 oleg_g 向您暗示的那样,混合了预处理器命令 (#define) 和 c++ typedef

在解析器处理结果代码之前处理预处理器指令(#define 等)。当您 typedef 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 

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

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

于 2013-01-23T14:28:00.040 回答