Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Including libtins in Qt



  • I included the libtins library in qt by project->add library option
    my code looks as follows
    samplelibtins.pro...........

    #-------------------------------------------------
    #
    # Project created by QtCreator 2016-11-02T13:03:33
    #
    #-------------------------------------------------
    
    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = samplelibtins
    TEMPLATE = app
    
    
    SOURCES += main.cpp\
            mainwindow.cpp
    
    HEADERS  += mainwindow.h
    
    FORMS    += mainwindow.ui
    
    LIBS += -ltins\
        -lWs2_32.lib\
         -lIphlpapi.lib
            -lwpcap\
             -lPacket\
    
    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -ltins
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -ltinsd
    
    INCLUDEPATH += $$PWD/include
    DEPENDPATH += $$PWD/include
    
    win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/lib/libtins.a
    else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/lib/libtinsd.a
    else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/lib/tins.lib
    else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/lib/tinsd.lib
    

    main.cpp..........

    #include "mainwindow.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    

    mainwindow.h.................

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    
    #define TINS_STATIC
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    private:
        Ui::MainWindow *ui;
    };
    
    #endif // MAINWINDOW_H
    

    mainwindow.cpp.....................

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include<include/tins/tins.h>
    #include<iostream>
    
    using namespace Tins;
    
    bool callback(const PDU &pdu) {
        const IP &ip = pdu.rfind_pdu<IP>(); // Find the IP layer
        const TCP &tcp = pdu.rfind_pdu<TCP>(); // Find the TCP layer
        std::cout << ip.src_addr() << ':' << tcp.sport() << " -> "
                  << ip.dst_addr() << ':' << tcp.dport() << std::endl;
        return true;
    }
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
         Sniffer("eth0").sniff_loop(callback);
        ui->setupUi(this);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    and when i run this code i get link error as follows:-

    mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall Tins::IPv4Address::IPv4Address(unsigned int)" (??0IPv4Address@Tins@@QAE@I@Z) referenced in function "public: class Tins::IPv4Address __thiscall Tins::IP::dst_addr(void)const " (?dst_addr@IP@Tins@@QBE?AVIPv4Address@2@XZ)
    
    mainwindow.obj:-1: 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 &)" (??6Tins@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV12@ABVIPv4Address@0@@Z) referenced in function "bool __cdecl callback(class Tins::PDU const &)" (?callback@@YA_NABVPDU@Tins@@@Z)
    
    mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: virtual __thiscall Tins::BaseSniffer::~BaseSniffer(void)" (??1BaseSniffer@Tins@@UAE@XZ) referenced in function "public: virtual __thiscall Tins::Sniffer::~Sniffer(void)" (??1Sniffer@Tins@@UAE@XZ)
    
    mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: class Tins::PacketWrapper<class Tins::PDU *,class Tins::Timestamp> __thiscall Tins::BaseSniffer::next_packet(void)" (?next_packet@BaseSniffer@Tins@@QAE?AV?$PacketWrapper@PAVPDU@Tins@@VTimestamp@2@@2@XZ) referenced in function "private: void __thiscall Tins::SnifferIterator::advance(void)" (?advance@SnifferIterator@Tins@@AAEXXZ)
    

    etc.......

    can someone help me to resolve this out?

    Edit: code tags - p3c0



  • I got the solution for this i just cleared the build and rebuilted the project again and it worked for me:-)

    Thank u



  • Hi,

    So u did clean , then run qmake , then build and run
    Which worked for u?.

    Thanks,



  • hi,
    @Pradeep Kumar

    i cleaned the makefiles in the project build folder and then builded the project in debug mode and then run....
    but now i find a problem when it is run in release mode the same error as above is appearing on building and runing the project.........



  • Hi,

    Delete the build folder and then delete pro.user in the project folder,
    then use the same way to build in debug and release mode.

    Thanks,



  • http://libtins.github.io/download/#download
    Try to follow the steps on this official page, it should work properly after you finish all the steps.


Log in to reply