ns_initparse的链接器错误

这里的代码

#include  #include  #include  #include  #include  int main (int argc, char *argv[]) { u_char nsbuf[4096]; char dispbuf[4096]; ns_msg msg; ns_rr rr; int i, j, l; if (argc < 2) { printf ("Usage: %s [...]\n", argv[0]); exit (1); } for (i = 1; i < argc; i++) { l = res_query (argv[i], ns_c_any, ns_t_mx, nsbuf, sizeof (nsbuf)); if (l < 0) { perror (argv[i]); } else { #ifdef USE_PQUERY /* this will give lots of detailed info on the request and reply */ res_pquery (&_res, nsbuf, l, stdout); #else /* just grab the MX answer info */ ns_initparse (nsbuf, l, &msg); printf ("%s :\n", argv[i]); l = ns_msg_count (msg, ns_s_an); for (j = 0; j < l; j++) { ns_parserr (&msg, ns_s_an, j, &rr); ns_sprintrr (&msg, &rr, NULL, NULL, dispbuf, sizeof (dispbuf)); printf ("%s\n", dispbuf); } #endif } } exit (0); } 

我编译为

gcc dns.c -lresolv

我收到以下链接器错误

在函数main': dns.c:(.text+0xd5): undefined reference to __ns_initparse’dn.c :(。text + 0x130):未定义引用__ns_parserr' dns.c:(.text+0x16a): undefined reference to __ns_sprintrr’

救命

链接解析器库有助于解决我的问题,我在编译命令中添加了-lresolv。

我相信你需要补充一下

 #include  

到你的文件