Linux 查找 pcap.h 和链接时出现问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13337349/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Problems finding pcap.h and linking
提问by Dr.Knowitall
I'm working on Fedora 17 and I want to program with libpcap. The problem is that my computer isn't finding pcap.h, which is really wierd since I've installed libpcap and libpcap-devel. Also wireshark and snort works on my station which I believe uses that library. So when I compile my code with ...
我在 Fedora 17 上工作,我想用 libpcap 编程。问题是我的电脑没有找到 pcap.h,这真的很奇怪,因为我已经安装了 libpcap 和 libpcap-devel。此外,wireshark 和 snort 也适用于我的工作站,我相信它使用了该库。所以当我编译我的代码时......
#include <pcap.h>
... Code
And use gcc my_file.c -lpcap, I get compiler errors that say ... can't find pcap.h. Whats odd is that I see my libpcap.so files in /libraries/ directory. I've done ..
并使用 gcc my_file.c -lpcap,我收到编译器错误说...找不到 pcap.h。奇怪的是我在 /libraries/ 目录中看到了我的 libpcap.so 文件。我弄完了 ..
yum install libpcap and yum install libpcap-devel
yum 安装 libpcap 和 yum 安装 libpcap-devel
I don't know why Fedora is doing this to me.
我不知道为什么 Fedora 会这样对我。
Thanks for any help!
谢谢你的帮助!
采纳答案by mata
You'll have to specify the folder where the headers are installed, for example:
您必须指定安装标头的文件夹,例如:
gcc -I/usr/include/pcap my_file.c -lpcap
Try locate pcap.h
to find the right directory to use with the -I
switch.
尝试locate pcap.h
找到与-I
交换机一起使用的正确目录。
回答by yeyo
Try
尝试
~$ whereis pcap
Then as mata said
然后就像马塔说的
gcc -lpcap -I{path} file.c
where {path}
is the path that whereis
gave you, you will choose the one with the pcap.h substring at the end (without the pcap.h part).
给您{path}
的路径在哪里whereis
,您将选择末尾带有 pcap.h 子字符串的路径(没有 pcap.h 部分)。
回答by GoTTimw
Your library might be missing, install it and link it
您的库可能丢失,安装并链接它
yum install libpcap-devel
In your makefile add:
在您的 makefile 中添加:
-L/usr/lib -lpcap
回答by Vilas Joshi
To execute the program in c++:
在 C++ 中执行程序:
for c++ program
对于 C++ 程序
g++ program_name.cpp -lpcap