declaration of C function int gethostname(char*, int)conflicts with previous declaration int gethostname(char*, size_t)

Hello All,

I am getting the below error while trying to compile my C++ code on Linux, I would appriciate if anybody could help me figure out how to solve this.

1
2
/home/myhome/ia-k_L/src/gias/src/db2/gias_CliApi.cc:53: error: declaration of C function int gethostname(char*, int) conflicts with
/xenv/OS/ia64/RH5.6AS_64/x86_64/usr/include/unistd.h:845: error: previous declaration int gethostname(char*, size_t) here


in file gias_CliApi.cc on line 53 I have the below declaration

extern "C" int gethostname(char *name, int namelen);

Many thanks.
Last edited on
C doesn't allow function overloading (different functions with the same name). unistd.h has already declared a function named gethostname, but with different parameter types.
Last edited on
Peter..

What ideallyy i should be doing in this scenario ? This code was compiling properly on Solaris platform but on linux it is giving problems..

Is there any way I can get out of this .?

Many thanks for your help.
What are you trying to do? Use the gethostname function declared in unistd.h or create your own function named gethostname?
Peter,

I searched the code I could see that there are all declarations in the code and this function is called just twice to get the machine name,

I think it should be safe to comment it out and use the gethostname function declared in unistd.h (as per your suggestion) . As any way its not performing any business logic so if the function declared in unistd.h give me the machine name then it should be fine...

Does that make sense to you ? ... or do you suggest some other approach..?

Many thanks.
Remove the prototype for gethostname() from gias_CliApi.cc. It's clearly wrong.
http://pubs.opengroup.org/onlinepubs/007908799/xns/gethostname.html
Topic archived. No new replies allowed.