* c++(gcc) & gethostbyname
@ 2001-02-02 11:06 Jouk Jansen
2001-02-03 10:48 ` Mark Garrett
2001-02-03 18:21 ` Dan Riley
0 siblings, 2 replies; 3+ messages in thread
From: Jouk Jansen @ 2001-02-02 11:06 UTC (permalink / raw)
Hi all,
Is it a known problem that c++(gcc) cannot include gethostbyname?
gcc, and Compaq's cc and cxx seem to work well (see example below)
Jouk
focus-jj) cc test.c
focus-jj) gcc test.c
focus-jj) ren test.c test.cpp
focus-jj) c++ test.cpp
/usr/ucb/ld:
Unresolved:
gethostbyname(char const *)
collect2: ld returned 1 exit status
focus-jj) cxx test.cpp
cat test.cpp
#include <netdb.h>
main()
{
struct hostent* he;
he = gethostbyname( "testje" );
}
focus-jj)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: c++(gcc) & gethostbyname
2001-02-02 11:06 c++(gcc) & gethostbyname Jouk Jansen
@ 2001-02-03 10:48 ` Mark Garrett
2001-02-03 18:21 ` Dan Riley
1 sibling, 0 replies; 3+ messages in thread
From: Mark Garrett @ 2001-02-03 10:48 UTC (permalink / raw)
in article 3A7AA2D0.5FCF4355@hrem.stm.tudelft.nl, Jouk Jansen at
joukj@hrem.stm.tudelft.nl wrote on 02/02/2001 22:06:
> Hi all,
>
> Is it a known problem that c++(gcc) cannot include gethostbyname?
> gcc, and Compaq's cc and cxx seem to work well (see example below)
>
> Jouk
>
>
>
>
> focus-jj) cc test.c
> focus-jj) gcc test.c
> focus-jj) ren test.c test.cpp
> focus-jj) c++ test.cpp
> /usr/ucb/ld:
> Unresolved:
> gethostbyname(char const *)
> collect2: ld returned 1 exit status
> focus-jj) cxx test.cpp
> cat test.cpp
Looks like your gcc is screwed up - it works for me :-
root@ned> cc -V
Compaq C V6.3-027 on Compaq Tru64 UNIX V5.1 (Rev. 732)
Compiler Driver V6.3-026 (sys) cc Driver
root@ned> cxx -V
Compaq C++ V6.3-003 for Compaq Tru64 UNIX V5.1 (Rev. 732)
Compiler Driver V6.3-003 (cxx) cxx Driver
root@ned> gcc --version
2.8.1
root@ned> cat test.c
#include <netdb.h>
main()
{
struct hostent* he;
he = gethostbyname( "testje" );
}
root@ned> cc test.c
root@ned> gcc test.c
root@ned> mv test.c test.cpp
root@ned> gcc test.cpp
Cheers
Mark ;)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: c++(gcc) & gethostbyname
2001-02-02 11:06 c++(gcc) & gethostbyname Jouk Jansen
2001-02-03 10:48 ` Mark Garrett
@ 2001-02-03 18:21 ` Dan Riley
1 sibling, 0 replies; 3+ messages in thread
From: Dan Riley @ 2001-02-03 18:21 UTC (permalink / raw)
Jouk Jansen <joukj@hrem.stm.tudelft.nl> writes:
> Is it a known problem that c++(gcc) cannot include gethostbyname?
Works here. Some version numbers might be helpful.
> focus-jj) c++ test.cpp
> /usr/ucb/ld:
> Unresolved:
> gethostbyname(char const *)
> collect2: ld returned 1 exit status
There's a hint there. Consider the program
extern void nosuchCC(char const*);
extern "C" void nosuchc(char const*);
main()
{
nosuchCC("asdf");
nosuchc("asdf");
}
Try compiling it with c++ -- you should see something like
dsr_lns130% g++ asdf.cc
/usr/bin/ld:
Unresolved:
nosuchCC(char const *)
nosuchc
collect2: ld returned 1 exit status
Now look back at your error message -- "gethostbyname(char const *)"
means it saw a prototype, but saw it in a C++ context, so it is
looking for a C++ mangled name. <netdb.h> is supposed to take care
of this via
_BEGIN_CPLUSPLUS
_END_CPLUSPLUS
lines that are translated into
extern "C" {
}
if __cplusplus is defined (all this in <standards.h>). Your error
means that for some reason this isn't happening. A 'c++ -E test.cpp'
to see what the preprocessor is doing might be enlightening.
--
Dan Riley dsr@mail.lns.cornell.edu
Wilson Lab, Cornell University <URL:http://www.lns.cornell.edu/~dsr/>
"History teaches us that days like this are best spent in bed"
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-02-03 18:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-02-02 11:06 c++(gcc) & gethostbyname Jouk Jansen
2001-02-03 10:48 ` Mark Garrett
2001-02-03 18:21 ` Dan Riley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox