Important: Please read the Qt Code of Conduct -

Windows add pcap to project

  • I am having some troubles with adding the pcap lib to my Qt project on windows

    I have tried multiple examples I've found here and on other websites but in the end I always have the same message "pcap.h No such file or directory" after trying to include it in my main.cpp file

    #include "mainwindow.h"
    #include <QApplication>
    #include <winsock2.h>
    #include <pcap.h>
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        MainWindow w;;
        return a.exec();

    This is what I have so far in my main.cpp

    # Project created by QtCreator 2018-05-28T03:27:57
    QT       += core gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = hello
    TEMPLATE = app
    SOURCES += main.cpp\
    HEADERS  += mainwindow.h\
    FORMS    += mainwindow.ui
    INCLUDEPATH += C:/WpdPack/Include
    LIBS += "-LC:/WpdPack/Lib" -lwpcap -lws2_32

    And this is my .pro file

    I installed WpdPack at the root of C:/

    Any idea why it autocompletes pcap.h when I'm including it but still displays an error when I compile/run it?

    Also I think it comes from the pcap.h file that has this line (and only this line)

    #include <pcap/pcap.h>


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What exact error do you have ?

  • @SGaist "pcap.h" no such file or diretory, and it's only for this .h file

  • Lifetime Qt Champion

    Where is that file located on your system ?

  • @SGaist C:/WpdPack/Include/pcap.h

  • Lifetime Qt Champion

    Then your include statement is wrong, it should just be #include <pcap.h>

  • @SGaist I still have the same error "pcap No such file or directory"

  • Okay so I ended up putting the header files directly into my project instead of writing the path in the .pro file
    Now it's working

Log in to reply