ns_initparse link problem
Eric Koldeweij <[email protected]>
| Newsgroups | gmane.linux.redhat.release.enigma |
|---|---|
| Message-ID | <[email protected]> |
ppl,
Can someone help me out with the following problem?
The problem is that when I try to compile a program which queries name
servers, it fails at the linking stage with the message "undefined
reference to `__ns_initparse'" and I cannot understand why. Here's the info:
[eric@sirius gethostinfo]$ gcc -Wall -g -o gethostinfo gethostinfo.c
-lresolv
/tmp/ccX1YbrX.o: In function `main':
/home/eric/src/gethostinfo/gethostinfo.c:41: undefined reference to
`__ns_initparse'
collect2: ld returned 1 exit status
[eric@sirius gethostinfo]$ strings --print-file-name /lib/*|grep
ns_initparse
/lib/libresolv-2.2.4.so: __ns_initparse
/lib/libresolv-2.2.4.so: ;; ns_initparse: %s
/lib/libresolv.so.2: __ns_initparse
/lib/libresolv.so.2: ;; ns_initparse: %s
So... I am linking against the resolver library, according to what I see
the ns_initparse function is in there and yet it cannot find it.....
Same is the case for other functions like ns_parserr() etc. What's the
catch here?
I'm using standard RedHat issue glibc-2.2.4-32 and gcc-2.96-112.7.2.
Compiling using gcc version 3 (gcc3-3.0.4-1) gives exactly the same results:
[eric@sirius gethostinfo]$ gcc3 -Wall -g -o gethostinfo gethostinfo.c
-lresolv
/tmp/ccSWrvut.o: In function `main':
/home/eric/src/gethostinfo/gethostinfo.c:41: undefined reference to
`__ns_initparse'
collect2: ld returned 1 exit status
I'm clueless, who knows what is going on here?
To make things complete, here's the source code, try for yourself:
----------------------- start source ------------------
#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/nameser.h>
#include <resolv.h>
/* #include "iso3166.h" */
#define BUFLEN 1024
char queryname[BUFLEN];
char answer[BUFLEN];
int main(int arg, char *argv[])
{
ns_msg handle;
int anslen;
strcpy(queryname,argv[1]);
/*
if (!getqueryname(argv[1]) || !(*queryname))
{
fprintf(stderr,"Could not find IP address for %s\n",argv[1]);
return 1;
}
*/
if (res_init() < 0)
{
fprintf(stderr,"Could not initialize resolver, exiting\n");
return 2;
}
if ((anslen = res_search(queryname,C_IN,T_A,answer,BUFLEN)) == -1)
{
herror("DNS query failed");
return 3;
}
ns_initparse(answer,anslen,&handle);
return 0;
}
---------------- end source ---------------
(As you can obviously see, this program is not finished yet. without the
ns_initparse I do get something back from the name server)