Orhan Tasci
Orhan Tasci

Reputation: 13

fatal error: pcap.h: No such file or directory remote: 34 | #include <pcap.h>

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?

Upvotes: 1

Views: 2530

Answers (1)

user16139739
user16139739

Reputation: 1155

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:

  1. 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.

  2. 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.

Upvotes: 1

Related Questions