我的操作系統是Windows 7旗艦版,x64。我用cmake,Visual Studio 12.0編譯了這個庫(https://github.com/mfontanini/libtins)。輸出是tins.lib。依賴項:Winpcap,IHPlpapi.lib和WS2_32.lib。 Winpcap似乎獨自工作,我得到了C:\ libtins \ Include中的所有內容以及C:\ libtins中除winpcap之外的所有.lib文件。 main.cpp源代碼來自庫例程。我無法理解有什麼問題,它似乎無法讀取一些功能。以下源代碼的編譯器是Qt Creator。靜態庫鏈接失敗
爲什麼庫無法與Qt Creator鏈接?此外,解決這個錯誤的解決方案是什麼?
Qt的項目文件是這樣的:
QT += core
QT -= gui
TARGET = libtins_test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:/WpdPack/Include
INCLUDEPATH += C:/libtins/Include
LIBS += -LC:/WpdPack/Lib/x64 -lwpcap -lpacket
LIBS += -LC:/libtins -lws2_32 -liphlpapi -ltins
main.cpp中是這樣的:
#include <tins/tins.h>
#include <map>
#include <iostream>
#include <functional>
#include <QCoreApplication>
using namespace Tins;
class arp_monitor {
public:
void run(Sniffer &sniffer);
private:
bool callback(const PDU &pdu);
std::map<IPv4Address, HWAddress<6>> addresses;
};
void arp_monitor::run(Sniffer &sniffer)
{
sniffer.sniff_loop(
std::bind(
&arp_monitor::callback,
this,
std::placeholders::_1
)
);
}
bool arp_monitor::callback(const PDU &pdu)
{
// Retrieve the ARP layer
const ARP &arp = pdu.rfind_pdu<ARP>();
// Is it an ARP reply?
if(arp.opcode() == ARP::REPLY) {
// Let's check if there's already an entry for this address
auto iter = addresses.find(arp.sender_ip_addr());
if(iter == addresses.end()) {
// We haven't seen this address. Save it.
addresses.insert({ arp.sender_ip_addr(), arp.sender_hw_addr()});
std::cout << "[INFO] " << arp.sender_ip_addr() << " is at "
<< arp.sender_hw_addr() << std::endl;
}
else {
// We've seen this address. If it's not the same HW address, inform it
if(arp.sender_hw_addr() != iter->second) {
std::cout << "[WARNING] " << arp.sender_ip_addr() << " is at "
<< iter->second << " but also at " << arp.sender_hw_addr()
<< std::endl;
}
}
}
return true;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
/*
if(argc != 2) {
std::cout << "Usage: " << *argv << " <interface>\n";
return 1;
}*/
arp_monitor monitor;
// Sniffer configuration
SnifferConfiguration config;
config.set_promisc_mode(true);
config.set_filter("arp");
// Sniff on the provided interface in promiscuous mode
Sniffer sniffer("eth0", config);
// Only capture arp packets
monitor.run(sniffer);
return a.exec();
}
編譯輸出(Qt創建者):
03:13:11: Running steps for project libtins_test...
03:13:11: Configuration unchanged, skipping qmake step.
03:13:11: Starting: "C:\Qt\Tools\QtCreator\bin\jom.exe"
C:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Debug
echo 1 /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 24 /* RT_MANIFEST */ "debug\\libtins_test.exe.embed.manifest">debug\libtins_test.exe_manifest.rc
if not exist debug\libtins_test.exe if exist debug\libtins_test.exe.embed.manifest del debug\libtins_test.exe.embed.manifest
if exist debug\libtins_test.exe.embed.manifest copy /Y debug\libtins_test.exe.embed.manifest debug\libtins_test.exe_manifest.bak
link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST /MANIFESTFILE:debug\libtins_test.exe.embed.manifest /OUT:debug\libtins_test.exe @C:\Users\burny1\AppData\Local\Temp\libtins_test.exe.3536.47.jom
main.obj : error LNK2019: unresolved external symbol "public: __cdecl Tins::IPv4Address::IPv4Address(unsigned int)" ([email protected]@@[email protected]@Z) referenced in function "public: class Tins::IPv4Address __cdecl Tins::ARP::sender_ip_addr(void)const " (? [email protected]@[email protected]@[email protected]@XZ)
main.obj : error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl Tins::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class Tins::IPv4Address const &)" ([email protected]@[email protected]? [email protected]@[email protected]@@[email protected]@[email protected]@[email protected]@Z) referenced in function "private: bool __cdecl arp_monitor::callback(class Tins::PDU const &)" ([email protected][email protected]@[email protected]@@@Z)
main.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl Tins::BaseSniffer::~BaseSniffer(void)" ([email protected]@@[email protected]) referenced in function "public: virtual __cdecl Tins::Sniffer::~Sniffer(void)" ([email protected]@@[email protected])
main.obj : error LNK2019: unresolved external symbol "public: class Tins::PacketWrapper<class Tins::PDU *,class Tins::Timestamp> __cdecl Tins::BaseSniffer::next_packet(void)" (? [email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected]) referenced in function "private: void __cdecl Tins::SnifferIterator::advance(void)" (? [email protected]@[email protected]@AEAAXXZ)
main.obj : error LNK2019: unresolved external symbol "public: class Tins::SnifferIterator __cdecl Tins::BaseSniffer::begin(void)" ([email protected]@[email protected]@[email protected]@XZ) referenced in function "public: void __cdecl Tins::BaseSniffer::sniff_loop<class std::_Bind<1,bool,struct std::_Pmf_wrap<bool (__cdecl arp_monitor::*)(class Tins::PDU const &),bool,class arp_monitor,class Tins::PDU const &>,class arp_monitor * const,class std::_Ph<1> &> >(class std::_Bind<1,bool,struct std::_Pmf_wrap<bool (__cdecl arp_monitor::*)(class Tins::PDU const &),bool,class arp_monitor,class Tins::PDU const &>,class arp_monitor * const,class std::_Ph<1> &>,unsigned int)" ([email protected]? [email protected][email protected][email protected]@[email protected]@@@[email protected]@@[email protected]@[email protected]@AEAV? [email protected][email protected]@@[email protected]@@[email protected]@@[email protected]$00_NU? [email protected][email protected]@[email protected]@@@[email protected]@@[email protected]@[email protected]@AEAV? [email protected][email protected]@@[email protected]@[email protected])
main.obj : error LNK2019: unresolved external symbol "public: class Tins::SnifferIterator __cdecl Tins::BaseSniffer::end(void)" ([email protected]@[email protected]@[email protected]@XZ) referenced in function "public: void __cdecl Tins::BaseSniffer::sniff_loop<class std::_Bind<1,bool,struct std::_Pmf_wrap<bool (__cdecl arp_monitor::*)(class Tins::PDU const &),bool,class arp_monitor,class Tins::PDU const &>,class arp_monitor * const,class std::_Ph<1> &> >(class std::_Bind<1,bool,struct std::_Pmf_wrap<bool (__cdecl arp_monitor::*)(class Tins::PDU const &),bool,class arp_monitor,class Tins::PDU const &>,class arp_monitor * const,class std::_Ph<1> &>,unsigned int)" ([email protected]? [email protected][email protected][email protected]@[email protected]@@@[email protected]@@[email protected]@[email protected]@AEAV? [email protected][email protected]@@[email protected]@@[email protected]@@[email protected]$00_NU? [email protected][email protected]@[email protected]@@@[email protected]@@[email protected]@[email protected]@AEAV? [email protected][email protected]@@[email protected]@[email protected])
main.obj : error LNK2019: unresolved external symbol "public: __cdecl Tins::Sniffer::Sniffer(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class Tins::SnifferConfiguration const &)" ([email protected]@@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) referenced in function main
main.obj : error LNK2019: unresolved external symbol "public: __cdecl Tins::SnifferConfiguration::SnifferConfiguration(void)" ([email protected]@@[email protected]) referenced in function main
main.obj : error LNK2019: unresolved external symbol "public: void __cdecl Tins::SnifferConfiguration::set_promisc_mode(bool)" (? [email protected]@[email protected]@[email protected]) referenced in function main
main.obj : error LNK2019: unresolved external symbol "public: void __cdecl Tins::SnifferConfiguration::set_filter(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (? [email protected]@[email protected]@[email protected][email protected]@[email protected]@V? [email protected]@[email protected]@[email protected]@@Z) referenced in function main
debug\libtins_test.exe : fatal error LNK1120: 10 unresolved externals
jom: C:\Qt\Tools\QtCreator\bin\build-libtins_test-Desktop_Qt_5_3_MSVC2013_64bit-Debug\Makefile.Debug [debug\libtins_test.exe] Error 1120
jom: C:\Qt\Tools\QtCreator\bin\build-libtins_test-Desktop_Qt_5_3_MSVC2013_64bit-Debug\Makefile [debug] Error 2
03:13:12: The process "C:\Qt\Tools\QtCreator\bin\jom.exe" exited with code 2.
Error while building/deploying project libtins_test (kit: Desktop Qt 5.3 MSVC2013 64bit)
When executing step "Make"
03:13:12: Elapsed time: 00:01.
問題到底是什麼? – 2014-10-18 00:28:12
錯誤LNK2019:編譯輸出中未解析的外部符號。 – random9823 2014-10-18 00:29:30
問題通常以問號結束。例如,「你的問題是什麼?」 – 2014-10-18 00:30:47