473,388 Members | 1,340 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

declaration of C function - conflicts

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

May 1 '06 #1
11 10938
* rh******@tampabay.rr.com:
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.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 1 '06 #2
rh******@tampabay.rr.com wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 1 '06 #3
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

May 1 '06 #4

Amit Limaye wrote:
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.

May 1 '06 #5
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

May 1 '06 #6
<rh******@tampabay.rr.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
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.
May 2 '06 #7

"Jim Langston" <ta*******@rocketmail.com> wrote in message
news:%e***************@fe05.lga...
<rh******@tampabay.rr.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
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()


Ooops, this should be
unistd::somefunction()
since unistd is the namespace name.
May 2 '06 #8
* Jim Langston:
<rh******@tampabay.rr.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
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.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 2 '06 #9
Jim Langston wrote:
<rh******@tampabay.rr.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
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.


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

May 2 '06 #10
Alf P. Steinbach wrote:
<rh******@tampabay.rr.com> wrote in message
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
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

May 2 '06 #11
rh******@tampabay.rr.com wrote:
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>

--
Ian Collins.
May 2 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Daniel Nichols | last post by:
I've noticed that in a C module (.c, .h file combination) that if you create a function's definition before it is used in other functions than a declaration is not necessary. I believe if the...
2
by: Rob Long | last post by:
Hi there Is there any way to access private variables directly from within a priviliged function? I have a situation where the priviliged function's execution context contains variables of the...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
1
by: novice | last post by:
Hi guys, I am getting the following errors while compiling my program. Since I have never encountered these errors before, I have no idea what is making them pop up. Any help would be great....
2
by: JeanDean | last post by:
Hi , I am trying to use "User-difned allocator " but on compilation it is giving conflicts for memcopy declarations with in string.h . Please refer the below code : any suggestions how to...
17
by: DanielJohnson | last post by:
how to use the combination function in python ? For example 9 choose 2 (written as 9C2) = 9!/7!*2!=36 Please help, I couldnt find the function through help.
2
by: Alan | last post by:
Does a template class declaration, like template <class T> have to come immediately prior to the declaration of the function, e.g., T do_something (T something) { . . . } that uses it?
23
by: nsa.usa | last post by:
Hi, I used to use a function in other languages (TP or asm don't remember) where I could get number of clockticks since 1980. Is there a similar function in C? I don't seem to find it. I need...
7
by: Sheldon | last post by:
Hi, This is a simple mistake so Iam sure there is someone who can help with it: The the file.h: #define IBFLEN 50000 int IRET, ILEN, IUNIT1, IUNIT2, ILOOP, KERR;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.