Reputation: 224
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)
and for the last one I have done like this
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
Upvotes: 0
Views: 1074
Reputation: 454
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.
Upvotes: 1