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 -= gui
CONFIG += c++17 console
CONFIG -= app_bundle
SOURCES +=
main.cpp
INCLUDEPATH += C:/Users/lucas/Desktop/prueba2/WpdPack/Include
LIBS += "-LC:/Users/lucas/Desktop/prueba2/WpdPack/Lib/x64"
DEFINES += WPCAP
DEFINES += HAVE_REMOTE
And in main.cpp I have:
#include <stdlib.h>
#include <stdio.h>
#include <pcap.h>
using namespace std;
**strong text**
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;
}
You only set the path to the library with
-L. You still have to also include the library with-l. This might be correct: