Question

I am getting the following error while compiling my source code:

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

The corresponding code which flags the error is:

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 

I request help in understanding the root cause of this error.

Thanks in advance.

Here are my machine and compiler details for reference:

$  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
$ 
Was it helpful?

Solution

lber.h defines ber_tag_t and ber_tag_t as follow:

    typedef impl_tag_t ber_tag_t;
    typedef impl_int_t ber_int_t;

In your code you try to redefine them, this is the case. A condition

    #ifndef ber_tag_t

is always true unless you defined ber_tag_t somewhere like

    #define ber_tag_t smth

OTHER TIPS

As oleg_g hints towards you are mixing preprocessor commands (#define) and c++ typedef

The preprocessor directives (#define etc.) are processed before the parser processes the resulting code. When you typedef ber_tag_t the preprocessor commands will never know of this and instead you need to #define a variable to indicate the type is defined.:

#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 

To clarify; preprocessor directives see only of other preprocessor variables as your code has not yet been interpreted at this point.

EDIT: I should also mention it may be beneficial to lay out your code in a way to avoid the need of this if possible. For example using a separate common header in which the inclusion and type are protected by include guards for example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top