Pcap 函数具有“未定义的引用" [英] Pcap functions have "undefined reference"

查看:88
本文介绍了Pcap 函数具有“未定义的引用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试完成本教程:http://www.tcpdump.org/pcap.html

I'm trying to go through this tutorial: http://www.tcpdump.org/pcap.html

现在我已经安装了 pcap(代码提示和所有工作):

Now I have install pcap (code hints and all that is working) using :

sudo apt-get install libpcap-dev

到目前为止我有以下代码(文件名是example_pcap.c):

and so far I have the following code (file name is example_pcap.c):

#include <stdio.h>
#include <pcap.h>

int main(int argc, char *argv[]) {
    char *dev, errbuf[PCAP_ERRBUF_SIZE];

    dev = pcap_lookupdev(errbuf);

    return 0;
}

根据我已经看到的许多问题,他们说使用这个编译它:

According to many questions I have seen already they said to compile it using this:

gcc -lpcap example_pcap.c -o example_pcap

但是我仍然收到以下错误:

However I still get the following error:

example_pcap.c:(.text+0x32): undefined reference to `pcap_lookupdev'

推荐答案

-lpcap 移到命令行末尾

请参阅为什么链接库的顺序有时会导致 GCC 出错?

这篇关于Pcap 函数具有“未定义的引用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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