To expand on jonprescott’s response…
When you build a product with Xcode, it’s built against an SDK. Each SDK is an amalgam of all the headers and libraries associated with a particular version of a platform. This is a key part of Xcode’s ability to do cross-platform builds, for example:
In modern versions of Xcode these SDKs are built in to Xcode. For example, Xcode 12.2 contains SDKs for macOS 10.14, iOS 12.2, watchOS 5.2, tvOS 12.2, and various simulator platforms. If you installed Xcode in the usual place, you can see a list of these SDKs as follows:
$ ls -l /Applications/Xcode.app/Contents/Developer/Platforms/*.platform/Developer/SDKs/
libpcap
is a supported API on macOS, so its headers and stub library are included in the macOS SDK:
$ find /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -name "*pcap*"
…
…/MacOSX.sdk/usr/include/pcap
…/MacOSX.sdk/usr/include/pcap/pcap-util.h
…/MacOSX.sdk/usr/include/pcap/pcap.h
…/MacOSX.sdk/usr/include/pcap-bpf.h
…/MacOSX.sdk/usr/include/pcap-namedb.h
…/MacOSX.sdk/usr/include/pcap.h
…/MacOSX.sdk/usr/lib/libpcap.tbd
…/MacOSX.sdk/usr/lib/libpcap.A.tbd
Note Each
.tbd
file is a stub library. Xcode uses this at link time as a stand-in for the shared library that get used at runtime.
Unless you need specific features that aren’t supported by the built-in
libpcap
, I recommend that you avoid installing your own version and instead use the system’s. This is as simple as:
Including the header:
#include <libpcap.h>
.
Adding
libpcap.tbd
to the Link Binary With Libraries build phase in your target.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"