英文:
fatal error: pcap.h: No such file or directory remote: 34 | #include <pcap.h>
问题
我遇到了这个问题,而最常见的解决方法(sudo apt-get install libpcap-dev
)对我不起作用。
我使用的是Mac,在尝试使用Homebrew安装时,它给出了以下提示:
"警告:没有可用的名为libpcap-dev
的配方。你是不是指的libpcap
?"
我该如何在Mac上安装libpcap-dev
及其依赖项,或者有什么其他解决方法?
英文:
I'm getting this issue and the most common solution (sudo apt-get install libpcap-dev
) isn't working for me.
I'm on a mac and when I try to install it using Homebrew it gives me:
"Warning: No available formula with the name "libpcap-dev
". Did you mean libpcap
?"
How can I install libpcap-dev
and it's dependencies on a mac or work around it?
答案1
得分: 1
我遇到了这个问题,而最常见的解决方法(sudo apt-get install libpcap-dev
)对我不起作用。
这是针对Debian和基于Debian的Linux发行版(如Ubuntu)的解决方案。如果这是最常见的解决方案,那可能只是因为很多人使用Debian、Ubuntu或其他Debian衍生版。
它不太可能适用于大多数其他Linux发行版,或者不是Linux发行版的操作系统,因为它们不使用Debian软件包管理器,而apt-get
依赖于它。
我在Mac上。
那么你可能正在运行的是macOS,而不是Debian,所以Debian的解决方案对你不起作用。
当我尝试使用Homebrew安装时
请注意,如果你在macOS上安装了Xcode或命令行编译器工具,那应该足以构建使用libpcap的软件- libpcap已经捆绑在macOS中,并且它的头文件已经捆绑在随Xcode和命令行编译器工具一起提供的软件开发工具包中。
例如:
$ cat foo.c
#include <stdio.h>
#include <pcap.h>
int
main(void)
{
printf("Hello, world!\n");
return 0;
}
$ cc -o foo -Os -Wall -W foo.c
$ ./foo
Hello, world!
这里没有“pcap.h: No such file or directory”错误。
当我尝试使用Homebrew安装时,它给我:Warning: No available formula with the name "libpcap-dev". Did you mean libpcap?
Homebrew是一个最初设计用于macOS而不是Linux的软件包管理器,并且不会像某些Linux发行版那样进行“这是库包,它安装了允许使用给定库的程序正常工作所需的内容;这是开发者包,它安装了允许编译使用给定库的程序所需的内容”区分。
因此,它没有单独的“libpcap”和“libpcap-dev”软件包,它只有一个“libpcap”软件包,它安装了一个版本的libpcap。
安装该软件包意味着你现在有两个版本的libpcap-一个是Apple提供的版本,另一个是Homebrew提供的版本。除非你需要最新版本的libpcap中的一些功能,而这些功能在你使用的macOS版本中提供的版本中没有,否则不需要这样做。
确保在你的Mac上安装了Xcode或命令行工具,然后你不应该收到报告找不到pcap.h的错误,除非你的程序或编译方式存在错误。如果你遇到这样的错误,请说明你正在编译什么,并给出该错误消息的上下文,例如:
1)如果pcap.h丢失,那么Clang(过去几年中Apple提供的C编译器)将显示类似以下的内容:
program.c:17:10: fatal error: 'pcap.h' file not found
#include <pcap.h>
^~~~~~~~
1 error generated.
2)我不知道“remote: 34”在这里是什么意思,因为“remote”不是C、C++或...源文件的名称。
英文:
> I'm getting this issue and the most common solution (sudo apt-get install libpcap-dev
) isn't working for me.
That's the solution for Debian and Debian-derived Linux distributions such as Ubuntu. If it's the most common solution, that's probably only because a lot of people use Debian, Ubuntu, or other Debian derivatives.
It is unlikely to work on most other Linux distributions, or on OSes that aren't Linux distributions, as they don't use the Debian package manager, which apt-get
depends on.
> I'm on a mac
Then you're probably running macOS, not Debian, so the Debian solution will not work for you.
> when I try to install it using Homebrew
Note that if you have either Xcode or the command-line compiler tools installed on macOS, that should be sufficient to build software that uses libpcap - libpcap is bundled with macOS, and its header files are bundled with the software development kits that come with Xcode and the command-line compiler tools.
For example:
$ cat foo.c
#include <stdio.h>
#include <pcap.h>
int
main(void)
{
printf("Hello, world!\n");
return 0;
}
$ cc -o foo -Os -Wall -W foo.c
$ ./foo
Hello, world!
No "pcap.h: No such file or directory" error there.
> when I try to install it using Homebrew it gives me: "Warning: No available formula with the name "libpcap-dev". Did you mean libpcap?"
Homebrew is a package manager that was originally designed for macOS, not for Linux, and doesn't make the same "there's the library package, which installs what's necessary to allow programs using a given library to work, and there's the developer package, which installs what's necessary to allow programs using a given library to be compiled" distinction that some Linux distributions make in their packages.
So it doesn't have separate "libpcap" and "libpcap-dev" packages, it just has a single "libpcap" package, that installs a version of libpcap.
Installing that package means you now have two versions of libpcap - the one Apple provides and the one Homebrew provides. Unless you need some of the features from the latest version of libpcap that aren't in the version that's provided with the version of macOS you're using, that shouldn't be necessary.
Make sure you have Xcode, or the command-line tools, installed on your Mac, and then you shouldn't get an error reporting that it couldn't find pcap.h, unless there's an error in your program or in the way you're compiling it. If you're getting an error like that, please indicate what you're compiling, and give the context of that error message, as:
-
If pcap.h were missing, then Clang (the C compiler that Apple has provided with Xcode for the past several years) will says something such as
program.c:17:10: fatal error: 'pcap.h' file not found
#include <pcap.h>
^~~~~~~~
1 error generated. -
I don't know what the heck "remote: 34" means there, as "remote" isn't the name of a C or C++ or... source file.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论