How to properly use exterenal lib pcap++
-
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.1The 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 ... } -
@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.).
-
Also you must not mix debug and release libraries - make sure the pcap library is linked against the same MSVC runtime as your app.
-
Also you must not mix debug and release libraries - make sure the pcap library is linked against the same MSVC runtime as your app.
@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-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?
@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.
-
@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.
@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.
-
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. -
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_32Could be something simple but i have little experiecne with libs.
