对于ns_initparse连接错误 [英] linker error for ns_initparse

查看:694
本文介绍了对于ns_initparse连接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,code

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/in.h>
#include <resolv.h>

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 <domain>[...]\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

gcc dns.c -lresolv

和我得到下面的连接错误

and I get the following linker error

在功能主要:
。dns.c :(文字+ 0xd5):未定义引用
__ ns_initparse
。dns.c :(文字+量0x130):未定义引用 __ ns_parserr
dns.c :(文字+ 0x16a):未定义引用
__ ns_sprintrr

In function main': dns.c:(.text+0xd5): undefined reference to __ns_initparse' dns.c:(.text+0x130): undefined reference to __ns_parserr' dns.c:(.text+0x16a): undefined reference to __ns_sprintrr'

帮助

推荐答案

我相信你需要添加

#include <arpa/nameser.h> 

到文件

这篇关于对于ns_initparse连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆