Winpcap help
-
Hello! I'm using version 6.3 of Qt Creator and I'm trying to use winpcacp version 4.1.2 library (I'm download from here https://www.winpcap.org/devel.htm). I am trying to run the first example code of the winpacp manual but I get the following errors and I do not know how to fix it:
:-1: error: debug/main.o:C:\Users\lucas\Desktop\build-prueba2-Desktop_Qt_6_3_1_MinGW_64_bit-Debug/../prueba2/main.cpp:22: undefined reference to `pcap_findalldevs_ex'
:-1: error: debug/main.o: in function `main':
C:\Users\lucas\Desktop\prueba2\main.cpp:44: error: undefined reference to `pcap_freealldevs'
:-1: error: collect2.exe: error: ld returned 1 exit status
:-1: error: [Makefile.Debug:68: debug/prueba2.exe] Error 1
Here is the code:
In .pro file I have:
QT -= guiCONFIG += c++17 console
CONFIG -= app_bundleSOURCES +=
main.cpp//# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += targetINCLUDEPATH += C:/Users/lucas/Desktop/prueba2/WpdPack/Include
LIBS += "-LC:/Users/lucas/Desktop/prueba2/WpdPack/Lib/x64"DEFINES += WPCAP
DEFINES += HAVE_REMOTEAnd in main.cpp I have:
#include <stdlib.h>
#include <stdio.h>
#include <pcap.h>using namespace std;
int main()
{
pcap_if_t *alldevs;
pcap_if_t *d;
int i=0;
char errbuf[PCAP_ERRBUF_SIZE];/* Retrieve the device list from the local machine */ if (pcap_findalldevs_ex((char*)PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1) { fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf); exit(1); } /* Print the list */ for(d= alldevs; d != NULL; d= d->next) { printf("%d. %s", ++i, d->name); if (d->description) printf(" (%s)\n", d->description); else printf(" (No description available)\n"); } if (i == 0) { printf("\nNo interfaces found! Make sure WinPcap is installed.\n"); } /* We don't need any more the device list. Free it */ pcap_freealldevs(alldevs); return 0;
}
-
@Pordo
Your lineLIBS += "-LC:/Users/lucas/Desktop/prueba2/WpdPack/Lib/x64"
tells the linker where to look for libraries. That's good. But you also have to tell it what library there you want it to link with. Something like
LIBS += "-LC:/Users/lucas/Desktop/prueba2/WpdPack/Lib/x64" -lpcap
See what I've added at the end? I thought you had something like this in your other post? Your instructions must tell you this, I don't know what the library is actually called.
-
-
sorry it's the first time I've used a forum, as it was a different code from an example that I saw I thought I had to open another post.
from the other post, today I try to put the path I put in this new code and Qt stop giving problems when compiling the #include<pcap.h>
the problem was that I was putting ...WpdPack/Lib and it was ...WpdPack/Lib/x64After that, I try to use the example from the manual and now I have this new problem. For your question Where exactly do you actually link with whatever "pcap" library, because I do not see anything? I don't know where I can check that
I see in another pages that the Winpcap have to linker but I dont know how to make that. I thought that with the INCLUDEPATH and LIBS I make this linker but I'm not sure
-
@Pordo
Your lineLIBS += "-LC:/Users/lucas/Desktop/prueba2/WpdPack/Lib/x64"
tells the linker where to look for libraries. That's good. But you also have to tell it what library there you want it to link with. Something like
LIBS += "-LC:/Users/lucas/Desktop/prueba2/WpdPack/Lib/x64" -lpcap
See what I've added at the end? I thought you had something like this in your other post? Your instructions must tell you this, I don't know what the library is actually called.