LINK2019 when using PCAP++

438 views Asked by At

I am trying to use the pcap++ library. I have downloaded the libraries for the VS2017, I linked the libraries and also the header files.

The libraries are:

Common++.lib
Packet++.lib
Pcap++.lib

and I made sure I am using the right release library.

When I build the solution, I am getting the error: LNK2019 unresolved external symbol _pcap_setfilter referenced in function "public: virtual bool __thiscall pcpp::IPcapDevice::setFilter

The code is simple:

#include "pch.h"
#include "IPv4Layer.h"
#include "Packet.h"
#include "PcapFileDevice.h"

int main(int argc, char* argv[])
{
    // open a pcap file for reading
    pcpp::PcapFileReaderDevice reader("1_packet.pcap");
    if (!reader.open())
    {
        printf("Error opening the pcap file\n");
        return 1;
    }

    reader.close();

    return 0;
}

Does anyone have any idea on how to resolve this?

2

There are 2 answers

2
sfc9982 On

I solve it by add:

#pragma comment(lib, "ws2_32.lib")
0
crazyChicken On

I added included path and libs to Qt .pro file. Pcap++ doesn't work alone. You can read Readme.txt file for more information. It needs dependencies those are Npcap or WinPcap. You should need to download SDK of those and include.

  • Make sure you have WinPcap or Npcap Developer's pack installed (WinPcap Dev Pack can be downloaded from winpcap, Npcap SDK can be downloaded from npcap)

I created external directory for external libraries. And I included libs to Qt .pro file:

INCLUDEPATH += \
    $$PWD/external/pcapplusplus/include/pcapplusplus \
    $$PWD/external/pcapplusplus/include \
    $$PWD/external/WpdPack/Include \
    $$PWD/external/WpdPack/Include/pcap \
    $$PWD/external/npcap/Include \
    $$PWD/external/npcap/Include/pcap \

LIBS += \
    -L$$PWD/external/pcapplusplus/lib -lPcap++ -lCommon++ -lPacket++ \
    -L$$PWD/external/WpdPack/Lib/x64 -lPacket -lwpcap \
    -L$$PWD/external/npcap/Lib/x64 -lPacket -lwpcap \

DEPENDPATH += \
    $$PWD/external/pcapplusplus/include/pcapplusplus \
    $$PWD/external/pcapplusplus/include \
    $$PWD/external/WpdPack/Include \
    $$PWD/external/WpdPack/Include/pcap \
    $$PWD/external/npcap/Include \
    $$PWD/external/npcap/Include/pcap \