Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to properly use exterenal lib pcap++
Forum Updated to NodeBB v4.3 + New Features

How to properly use exterenal lib pcap++

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    How to properly use exterenal lib pcap++?

    Using msvc2015 sp3 as compiler and libs for same compiler.
    pcapplusplus-22.05-windows-vs2015 and npcap-sdk-0.1

    The example below crashes without error msg.

    .pro

    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    CONFIG += c++11
    
    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
        main.cpp \
        mainwindow.cpp
    
    HEADERS += \
        mainwindow.h
    
    FORMS += \
        mainwindow.ui
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    
    
    
    INCLUDEPATH += $$PWD/npcap-sdk-0.1/Include
    LIBS += -L$$PWD/npcap-sdk-0.1/Lib/x64 -lwpcap -lpacket -lws2_32
    LIBS += -L$$PWD/npcap-sdk-0.1/Lib/x64 -lwpcap -lws2_32
    
    INCLUDEPATH += $$PWD/pcapplusplus-22.05-windows-vs2015/header
    LIBS +=      -L$$PWD/pcapplusplus-22.05-windows-vs2015/x64/Release -lCommon++ -lPacket++ -lPcap++        
    
    

    Minimal usage of lib:

    //ext lib includes
    #include "Packet.h"
    #include "PayloadLayer.h"
    #include "PcapFileDevice.h"<-- related include
    
    ...
    
    void MainWindow::on_problem_clicked()
    {
    
        pcpp:: IFileReaderDevice* r;
    
        r=pcpp::IFileReaderDevice::getReader("");//<----- crashes here, on program start, before accessing function ...
    
    
    }
    
    
    

    libs + project minimal download link

    pcap++ lib dl link

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mchinand
      wrote on last edited by
      #2

      @Q139 said in How to properly use exterenal lib pcap++:

      r=pcpp::IFileReaderDevice::getReader("")

      This isn't a Qt question. Does the argument passed to this method need to be an existing file (or maybe at least a non-empty string)? You can validate what you pass to this method before you call it (is it an existing file, does it specify a writeable file location, etc.).

      1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Also you must not mix debug and release libraries - make sure the pcap library is linked against the same MSVC runtime as your app.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        ? 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          Also you must not mix debug and release libraries - make sure the pcap library is linked against the same MSVC runtime as your app.

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by A Former User
          #4

          @Christian-Ehrlicher said in How to properly use exterenal lib pcap++:

          make sure the pcap library is linked against the same MSVC runtime as your app

          How to check the .lib file version and how to set compiler up for same version?

          Christian EhrlicherC 1 Reply Last reply
          0
          • ? A Former User

            @Christian-Ehrlicher said in How to properly use exterenal lib pcap++:

            make sure the pcap library is linked against the same MSVC runtime as your app

            How to check the .lib file version and how to set compiler up for same version?

            Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Q139 said in How to properly use exterenal lib pcap++:

            How to check the .lib file version and how to set compiler up for same version?

            Ask the creator of the lib.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            ? 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @Q139 said in How to properly use exterenal lib pcap++:

              How to check the .lib file version and how to set compiler up for same version?

              Ask the creator of the lib.

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              @Christian-Ehrlicher said in How to properly use exterenal lib pcap++:

              @Q139 said in How to properly use exterenal lib pcap++:

              How to check the .lib file version and how to set compiler up for same version?

              Ask the creator of the lib.

              I see. Thanks for previous post , probably directed right way.

              1 Reply Last reply
              0
              • Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                A debug version normally ends with a 'd' in the library name but it might be different here - don't know.
                If you build in debug mode try it with release and see if it still crashes.
                Also you can use Dependency Walker to see if the msvcrtxxx.dll or msvcrtxxxD.dll is used - when both are used something is wrong and your app will most likely crash.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by A Former User
                  #8

                  Built the pcap++ lib using msvc2015 , on same PC as msvc2015 compililer used in Qt.
                  To build pcap++ it required pthreads32 and npcap-sdk or winCap sdk.
                  Tryed building the lib with both. Unfortunately both created same crash if using the lib in Qt, same as using pcap++ prebuilt version msvc2015 .
                  Also building and running debug version crashed and no error codes visible.
                  The pcap lib probably is fine, but linking it or the additional lib depencencies to qt appear to crash the app instantly.

                  In addition i had to include to qt PRO file the npcap sdk to get rid of missing dependencies:

                  INCLUDEPATH += $$PWD/npcap-sdk-0.1/Include
                  LIBS += -L$$PWD/npcap-sdk-0.1/Lib/x64 -lwpcap -lPacket
                  LIBS += -lws2_32

                  Could be something simple but i have little experiecne with libs.

                  alt text

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved