0

I am programming a networking tool which uses Winpcap.I am using Visual Studio 2017 . Winpcap is a external library which I have to use in my program by including pcap.h. Of course I know these :

(1) The compiler needs to know where the header is located.

(2) The linker needs to know where the .lib file is located, and the lib file name

so for the first one I add the path of include directory form the next step(like image) enter image description here

and for the last one I have done like this enter image description here

and now I have a communicator class like this

#include<pcap.h>
#pragma once
class Communicator
{
    public:
    pcap_if_t *alldevs;
    pcap_t *fp;
    int findAllDevice(void);
    //int openAdapter(char* _name);
    //void readNexLoop(void);
    //void startCommunicator(void);
    Communicator();
    ~Communicator();
};

cpp file :

#include "stdafx.h"
#include "Communicator.h"

//#include<thread>
Communicator::Communicator()
{
}


Communicator::~Communicator()
{
}
int Communicator::findAllDevice()
{
int result = -1;
char errbuf[PCAP_ERRBUF_SIZE + 1];

result = pcap_findalldevs(&alldevs, errbuf);
//result = pcap_findalldevs(&alldevs, errbuf);
//pcap_freealldevs(alldevs);
return result;
}

but when I build it, there are Errors

    Error   LNK2019 unresolved external symbol _pcap_findalldevs referenced in function "public: int 
            __thiscall Communicator::findAllDevice(void)" (?findAllDevice@Communicator@@QAEHXZ)  
    MobinServer2.0  D:\MobinServer2.0\MobinServer2.0\Communicator.obj   1   

Can anyone shed some light on this, what am i doing wrong? I need to help this please help me solve. Thank you

Hadi Mirzaei
  • 222
  • 2
  • 16
  • you have to name library as well, directory not enough, did you name it properly? – Swift - Friday Pie Sep 12 '20 at 10:02
  • @Hadi Have you indicated to include the actual library file(s) to the linker? (In the "Input" tab under "Linker" options). You have told the linker where to find the library but maybe forgotten to tell it which `.lib` fies to actually use. – Adrian Mole Sep 12 '20 at 10:03
  • @Adrian Mole in those 'open file dialogs' you can not tell the linker to find a specific '.lib' file, you just tell the linker to select the folder – Hadi Mirzaei Sep 12 '20 at 10:08
  • @Swift - Friday Pie could you explain more? – Hadi Mirzaei Sep 12 '20 at 10:17
  • 2
    Look at Linker->Input in the list to the left. There is an input line in the dialog that opens, which you can expand to a list of all libraries currently used. Some types of projects already have some there,some not. You need to add the full library name with extension there. Repeat the same if you change project type,such as debug, release, or some other type. – DNT Sep 12 '20 at 10:21
  • Also, keep in mind that you have to use [this](https://nmap.org/npcap/windows-10.html) WinPcap and not the [deprecated](https://www.winpcap.org/) one – kesarling He-Him Sep 12 '20 at 10:29
  • Does this answer your question? [PCAP Program in Visual Studio](https://stackoverflow.com/questions/30549917/pcap-program-in-visual-studio) – kesarling He-Him Sep 12 '20 at 10:31

1 Answers1

1

It is not enough to add a directory for additional libraries, you also need to add the library itself as a dependency. Header files sometimes do that on your behalf, this one apparently does not.