declaration of C function - conflicts

R

rherring

Hello,
I have some C++ code that builds against 2 headers files that contain
the same function name declaration (gethostname).
The header files are not directly included. They are included via
other header files.

How can I resovle this error?

The error (GCC 3.3.2 on Solaris 9):
/usr/include/unistd.h:278: error: declaration of C function `int
gethostname(char*, unsigned int)' conflicts with
.../../../webserver_api/apache/SunOS/include/ap_config.h:189: error:
previous
declaration `int gethostname(char*, int)' here
 
A

Alf P. Steinbach

* (e-mail address removed):
Hello,
I have some C++ code that builds against 2 headers files that contain
the same function name declaration (gethostname).
The header files are not directly included. They are included via
other header files.

How can I resovle this error?

The error (GCC 3.3.2 on Solaris 9):
/usr/include/unistd.h:278: error: declaration of C function `int
gethostname(char*, unsigned int)' conflicts with
../../../webserver_api/apache/SunOS/include/ap_config.h:189: error:
previous
declaration `int gethostname(char*, int)' here

Look up the PIMPL pattern.
 
V

Victor Bazarov

I have some C++ code that builds against 2 headers files that contain
the same function name declaration (gethostname).
The header files are not directly included. They are included via
other header files.

How can I resovle this error?

The error (GCC 3.3.2 on Solaris 9):
/usr/include/unistd.h:278: error: declaration of C function `int
gethostname(char*, unsigned int)' conflicts with
../../../webserver_api/apache/SunOS/include/ap_config.h:189: error:
previous
declaration `int gethostname(char*, int)' here

Find (or create) a macro by defining which you will disable one of the
conflicting declarations. Then define that macro only for the module
that gives you the error when compiled.

V
 
A

Amit Limaye

Did u build the source urself ?
Is the binary of the Apache for ur system as also the supporting
libraries. Things like this should be taken care of in the configure
process ?

-SIGTERM
amit
 
R

rherring

Amit said:
Did u build the source urself ?
Is the binary of the Apache for ur system as also the supporting
libraries. Things like this should be taken care of in the configure
process ?

-SIGTERM
amit

I am using the apache API to build a custom module. When building my
module I get the error. This just started happening when I upgraded
the GCC complier from 2.95 to 3.3.2.
 
A

Amit Limaye

precisely cause the apache libraries would define their own version int
gethostname if they dont find one in the unistd.h .
Now tht u have changed header files its complaining abt this. try
reverting back to the old compiler or recompiling the apache API for
the new compiler
if u check the ap_config.h the gethostbyname function must be protected
by #ifndef macros which will be defined in the build process. Check
config.h to see if the macro was defined

-SIGTERM
amit
 
J

Jim Langston

Hello,
I have some C++ code that builds against 2 headers files that contain
the same function name declaration (gethostname).
The header files are not directly included. They are included via
other header files.

How can I resovle this error?

The error (GCC 3.3.2 on Solaris 9):
/usr/include/unistd.h:278: error: declaration of C function `int
gethostname(char*, unsigned int)' conflicts with
../../../webserver_api/apache/SunOS/include/ap_config.h:189: error:
previous
declaration `int gethostname(char*, int)' here

It is exactly the reason namespaces were created, to get rid of this
problem. What is happening is that the function gethostname is being
defined in two different headers.

What you might try (which may or may not work) is put one of the headers
inside a namespace. I dont' know what your headers look like so again, this
may or may not work.

namespace unistd
{
#include "unistd.h"
}
#include "ap_config.h"

Hopefully this will compile (not guaranteed, I haven't tried it).

Then you would need to specify the namespace for using the functions inside
of unistd.h
unistd.h::somefunction()

I'm not sure if namespace xxx {] requires a ; at the end or not.

All you can do is try. I think you probably only have about a 25% of this
actually working, but it's worth a shot.
 
J

Jim Langston

Jim Langston said:
It is exactly the reason namespaces were created, to get rid of this
problem. What is happening is that the function gethostname is being
defined in two different headers.

What you might try (which may or may not work) is put one of the headers
inside a namespace. I dont' know what your headers look like so again,
this may or may not work.

namespace unistd
{
#include "unistd.h"
}
#include "ap_config.h"

Hopefully this will compile (not guaranteed, I haven't tried it).

Then you would need to specify the namespace for using the functions
inside of unistd.h
unistd.h::somefunction()

Ooops, this should be
unistd::somefunction()
since unistd is the namespace name.
 
A

Alf P. Steinbach

* Jim Langston:
Hello,
I have some C++ code that builds against 2 headers files that contain
the same function name declaration (gethostname).
The header files are not directly included. They are included via
other header files.

How can I resovle this error?

The error (GCC 3.3.2 on Solaris 9):
/usr/include/unistd.h:278: error: declaration of C function `int
gethostname(char*, unsigned int)' conflicts with
../../../webserver_api/apache/SunOS/include/ap_config.h:189: error:
previous
declaration `int gethostname(char*, int)' here

It is exactly the reason namespaces were created, to get rid of this
problem. What is happening is that the function gethostname is being
defined in two different headers.

What you might try (which may or may not work) is put one of the headers
inside a namespace. I dont' know what your headers look like so again, this
may or may not work.

namespace unistd
{
#include "unistd.h"
}
#include "ap_config.h"

Hopefully this will compile (not guaranteed, I haven't tried it).

Then you would need to specify the namespace for using the functions inside
of unistd.h
unistd.h::somefunction()

I'm not sure if namespace xxx {] requires a ; at the end or not.

All you can do is try. I think you probably only have about a 25% of this
actually working, but it's worth a shot.

Putting a C-oriented header in a namespace /can/ work when the functions
are 'extern "C"'. §7.3.4/1 has an example where an 'extern "C"'
function declaration in two different namespaces refer to the same
function (as one would expect). However, practically there is a problem
with macro definitions, which abound in C-oriented headers.
 
J

Jonathan Mcdougall

Jim said:
It is exactly the reason namespaces were created, to get rid of this
problem. What is happening is that the function gethostname is being
defined in two different headers.

What you might try (which may or may not work) is put one of the headers
inside a namespace. I dont' know what your headers look like so again, this
may or may not work.

It won't work, unless you put the function definitions in that
namespace too and recompile the library. The thing is, unistd.h is a
standard header on unix and ap_config.h is bundled with Apache.
namespace unistd
{
#include "unistd.h"
}
#include "ap_config.h"

Hopefully this will compile (not guaranteed, I haven't tried it).

It may compile (though I suspect it won't), but it certainly won't
link.
Then you would need to specify the namespace for using the functions inside
of unistd.h
unistd.h::somefunction()

Perhaps you meant

unistd::somefunction()

?
I'm not sure if namespace xxx {] requires a ; at the end or not.

It does not (why didn't you check?)
All you can do is try. I think you probably only have about a 25% of this
actually working, but it's worth a shot.

Uhh, no, I don't think it is.

To the OP: I suspect these headers are compiled with a C compiler,
because you should get two overloaded functions named gethostname() in
C++.

Perhaps your best bet would be to find a way of preventing one of these
headers (ap_config.h most probably) from declaring this function. There
may be some macros/options available to configure the build. Contacting
the library maintainers could help you.


Jonathan
 
J

Jonathan Mcdougall

Putting a C-oriented header in a namespace /can/ work when the functions
are 'extern "C"'. §7.3.4/1 has an example where an 'extern "C"'
function declaration in two different namespaces refer to the same
function (as one would expect). However, practically there is a problem
with macro definitions, which abound in C-oriented headers.

The problem here is that the function declarations are different (one
with an int and the other with an unsigned int). This won't work if
both are extern "C".


Jonathan
 
I

Ian Collins

Hello,
I have some C++ code that builds against 2 headers files that contain
the same function name declaration (gethostname).
The header files are not directly included. They are included via
other header files.

How can I resovle this error?

The error (GCC 3.3.2 on Solaris 9):
/usr/include/unistd.h:278: error: declaration of C function `int
gethostname(char*, unsigned int)' conflicts with
.../../../webserver_api/apache/SunOS/include/ap_config.h:189: error:
previous
declaration `int gethostname(char*, int)' here
<OT>
Check your config headers, and options, it's usual for the config script
to check for standard system calls. If you change your compiler, run
the config process again.
</OT>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top