From: Dan Riley <dsr@mail.lns.cornell.edu>
Subject: Re: c++(gcc) & gethostbyname
Date: 03 Feb 2001 13:21:49 -0500 [thread overview]
Message-ID: <shu26br5j6.fsf@lns130.lns.cornell.edu> (raw)
In-Reply-To: 3A7AA2D0.5FCF4355@hrem.stm.tudelft.nl
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"
prev parent reply other threads:[~2001-02-03 18:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox