ubuntu下使用eclipse调用libpcap库编写一个小程序时出的错误:pcap.h没有参与编译
来源:互联网 发布:泉州猴子网络seo 编辑:程序博客网 时间:2024/05/22 17:44
这段程序是winpcap或者libpcap编程者第一次要尝试的东东,仿佛就是helloworld之余C,但还是让我挠头了一天。
#include "pcap.h"int main(){ pcap_if_t *alldevs; pcap_if_t *d; int i=0; char errbuf[PCAP_ERRBUF_SIZE]; /* 获取本地机器设备列表 */ if (pcap_findalldevs(&alldevs, errbuf) == -1) { fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf); return 1; } /* 打印列表 */ for(d= alldevs; d != NULL; d= d->next) { printf("%d. %s", ++i, d->name); if (d->description) printf(" (%s)\n", d->description); else printf(" (No description available)\n"); } if (i == 0) { printf("\nNo interfaces found! Make sure WinPcap is installed.\n"); return 1; } /* 不再需要设备列表了,释放它 */ pcap_freealldevs(alldevs); return 1;}
情况:
【1】原本是winpcap介绍中用到的程序,由于winpcap与libpcap的兼容性,我就从win32下拿到了ubuntu下,当然也是有变化:
pcap_findalldevs函数在win32下已经加了_ex,you know what i mean,但是libpcap下还是上文给出的样子。【2】 直接gcc -o getdevs getdevs.c -lpcap 运行ok,./getdevs也成功显示了网卡及描述;
【3】问题是:我把源码放到eclipse的c project中,就不行了(以前没怎么用过),这次算领教了。
明明在源文件中点击pcap.h都能链接到头文件,但是下面的相关函数和变量都表示undefined reference, 邪了门了。
当然,我们看上面得gcc编译也发现还有一个参数-lpcap,但是在eclipse中这个参数怎么加呢?
直接在run as..中加是不行的,run的前提是你build要通过,这里build都通不过,那就是到项目Properties中添加:
我个人的艰辛就不说了,直接说找来的答案了吧:
I had the same problem in Eclipse. I order to link this library to your project, right click the project in "Project Explorer" (short view) and choose "Properties". On the left go to "C/C++ Build" > "Settings" and on the "Settings" panel go to "Tool Settings" > "GCC C Linker" (if this is your compiler) > "Libraries" > and add the word "pcap" in the list titled "Libraries (-l)". Press "Apply" on the bottom and then "OK". Click "Project" > "Build All" and this should do the job. It should be no errors now. :)
答案来自:http://ubuntuforums.org/archive/index.php/t-125444.html 感谢!
如果再遇到这种编译需要的参数,你知道向那里加了么,呵呵。
- ubuntu下使用eclipse调用libpcap库编写一个小程序时出的错误:pcap.h没有参与编译
- libpcap中<pcap.h>定义的结构
- libpcap中<pcap.h>的平台无关性之条件编译
- libpcap中<pcap.h>中定义的函数
- ubuntu 编译内核时出的错误
- Ubuntu 下使用Eclipse编译、调试嵌入式程序的方法
- Ubuntu下使用Eclipse编译pthread程序错误undefined reference to `pthread_create'
- linux下安装pcap qt使用pcap.h
- 使用libpcap库过滤pcap文件中的数据包
- ubuntu 14.04 下编译QT程序出错误:can't find -lGL error
- Ubuntu 下使用Eclipse编译、调试嵌入式程序的方法(下)
- 使用WinPcap和libpcap类库读写pcap文件(002)PCAP文件格式
- window环境下使用ndk编译出android studio/Eclipse能使用的ffmpeg动态库
- 利用pcap编写自己的sniffer程序
- 利用pcap编写自己的sniffer程序
- Ubuntu下函数使用“math.h"编译出现的问题
- Ubuntu下 交叉编译树莓派内核时出现错误“没有那个文件或目录” 的解决办法
- ubuntu下libpcap的安装
- 二项堆
- android多点触控
- Android NDK 开发的栈错误调试
- 好程序需要至少写两遍
- iPawn:文艺青年的玩桌游方式
- ubuntu下使用eclipse调用libpcap库编写一个小程序时出的错误:pcap.h没有参与编译
- 带有ListView界面左右滑动,切换界面
- 在OpenSSL中添加自定义加密算法
- 谢国忠
- hdu_2040_亲和数
- 程序如何捕捉signal函数参数中指定的信号
- 系统——进程线程,同步与通信
- 用Python将字符串里的英文双引号转换成中文双引号
- vs快捷键大全