From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,d4aeb8258ef21e73,start X-Google-Attributes: gidfee84,public From: lucia@savvy.zko.dec.com (Tim Lucia) Subject: Re: Help needed on C++ libs Date: 1995/08/25 Message-ID: <41lbgk$hdu@nntpd.lkg.dec.com>#1/1 X-Deja-AN: 108833749 distribution: world references: <40nmpd$t2l@infoserv.rug.ac.be> organization: Digital Equipment Corporation reply-to: lucia@zko.dec.com newsgroups: comp.unix.osf.osf1 In article <40nmpd$t2l@infoserv.rug.ac.be>, Christophe Colle writes: |>Hi, |> |>I'm new to c++. I just installed cxx and g++. When I try to compile following |>code i get some linking errors.. When I compile I compile the C version |>with gcc and cc, there is no error. What is wrong? |> |>code : |>#include |>#include |>#include |>#include |>#include |>#include |>#include |> |> |>main() |>{ |> struct hostent *ptr=gethostbyname((char *)0l); |> |>} |> |>colle@krtkg1> g++ t.cc |>/usr/bin/ld: |>Unresolved: |>gethostbyname__FPCc |>collect2: ld returned 1 exit status |>colle@krtkg1> cxx t.cc |>t.cc:18: warning: The procedure "main" returns a non-void value but does not |>contain a return statement. |>ld: |>Error: Undefined: |>gethostbyname__XPCc |> This is due to the fact that the compiler mangled the name of 'gethostbyname' for type-safe linkage, as described in your basic C++ text. The problem is with netdb.h not being C++-safe on your version of the o/s. You don't say what version of Digital UNIX you are running, by my 3.2 system has C++-safe header files. If you only want to declare gethostbyname, then you should say: extern "C" { extern struct hostent *gethostbyname __((const char *)); } Regards, Tim -- Timothy J. Lucia - DECladebug Email: mailto:lucia@zko.dec.com Digital Equipment Corporation Phone: 603.881.2615 110 Spitbrook Road ZKO2-3/K06 Fax: 603.881.0120 Nashua, NH USA 03062-2698 I'd rather be bicycling.