如何解决错误“未定义对‘pcap_parse’的引用”
我正在尝试在 C++ 程序中使用 libpcap 库。
我已经下载了libpcap-1.0.0.tgz
,解压了它,然后
./configer
make
make install
我有了libpcap.a
和headers
,并且我有编写了一个示例程序来测试它。但它给了我编译器错误,如下所示:
/usr/local/lib/libpcap.a(gencode.o): In function `.L151':
gencode.c:(.text+0x7f4): undefined reference to `pcap_parse'
collect2: ld returned 1 exit status
我正在使用以下命令编译该程序:
g++ -o test test.cpp -lpcap
我在构建 libpcap 和 headers 时做错了什么吗?
I am trying to use the libpcap library in a C++ program.
I have downloaded libpcap-1.0.0.tgz
, untared it, and then
./configer
make
make install
I have libpcap.a
and headers
with me, and I have written one sample program to test it. But it is giving me compiler errors as follows:
/usr/local/lib/libpcap.a(gencode.o): In function `.L151':
gencode.c:(.text+0x7f4): undefined reference to `pcap_parse'
collect2: ld returned 1 exit status
I am compiling this program using following command:
g++ -o test test.cpp -lpcap
Am i doing anything wrong in building libpcap
and headers
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我很确定您需要在
test.cpp
之前传递-lpcap
I'm pretty sure you need to pass
-lpcap
beforetest.cpp
尝试安装 libstdc++-4.8-dev - 当我遇到类似问题时,这对我有用。
Try installing libstdc++-4.8-dev - this worked for me when I had a similar issue.
你必须使用此命令安装 Libpcap-devel ( sudo apt-get install libpcap-dev ) 如果它不起作用也安装 flex (sudo apt-get install bison )
祝你好运
You have to install Libpcap-devel using this command ( sudo apt-get install libpcap-dev ) if it doesn't work install flex too (sudo apt-get install bison)
good luck
包含在运行 ./configure 和 make 后生成的 Grammar.c。
Include grammar.c which gets generated after you run ./configure and make.