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

libtins



  • I have problems with the libtins library http://libtins.github.io/
    I received the tins.lib file by intent (compiled VS 2017).
    I created a new Qt Console Application project.
    Build system: qmake.
    Kit selection: MSVC 2017 32bit https://ibb.co/Lh8Zb7R (MSVC 2015 64bit I have an error compiling any project).
    For tins.lib I added an external library https://ibb.co/dWxV606
    main.cpp

    #define TINS_STATIC
    #include <QCoreApplication>
    #include <iostream>
    #include <tins/tins.h>
    
    using namespace Tins;
    using namespace std;
    
    bool callback(const PDU &pdu) {
        // Find the IP layer
        const IP &ip = pdu.rfind_pdu<IP>();
        // Find the TCP layer
        const TCP &tcp = pdu.rfind_pdu<TCP>();
        cout << ip.src_addr() << ':' << tcp.sport() << " -> "
             << ip.dst_addr() << ':' << tcp.dport() << endl;
        return true;
    }
    
    int main(int argc, char *argv[]) {
        QCoreApplication a(argc, argv);
        Sniffer("eth0").sniff_loop(callback);
        return a.exec();
    }
    

    untitled2.pro

    QT -= gui
    
    CONFIG += c++11 console
    CONFIG -= app_bundle
    
    # The following define makes your compiler emit warnings if you use
    # any Qt feature that has been marked deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
            main.cpp
    
    INCLUDEPATH +=C:/Users/HOME/Desktop/lab_2/new/libtins\include
    INCLUDEPATH +=C:/WpdPack_4_1_2/WpdPack/Include
    
    LIBS += C:/WpdPack_4_1_2/WpdPack/Lib/wpcap.lib \
            C:/WpdPack_4_1_2/WpdPack/Lib/packet.lib \
            C:/Users/HOME/Desktop/xx/ws2_32.lib \
            C:/Users/HOME/Desktop/xx/iphlpapi.lib \
            #C:/Users/HOME/Desktop/lab_2/new/libtins/build/lib/Debug/tins.lib \
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    win32: LIBS += -L$$PWD/../lab_2/new/libtins/build/lib/Debug/ -ltins
    
    INCLUDEPATH += $$PWD/../lab_2/new/libtins/include/tins
    DEPENDPATH += $$PWD/../lab_2/new/libtins/include/tins
    
    win32:!win32-g++: PRE_TARGETDEPS += $$PWD/../lab_2/new/libtins/build/lib/Debug/tins.lib
    else:win32-g++: PRE_TARGETDEPS += $$PWD/../lab_2/new/libtins/build/lib/Debug/libtins.a
    

    There are a few errors https://ibb.co/rcKGWLK

    LNK2019 unresolved external symbol __imp__inet_pton@12 referenced in function "private: unsigned int __thiscall Tins::IPv4Address::ip_to_int(char const *)" (?ip_to_int@IPv4Address@Tins@@AAEIPBD@Z) ip_address.obj
    LNK2001	unresolved external symbol __imp__inet_pton@12 ipv6_address.obj
    LNK2019	unresolved external symbol _inet_ntop@16 referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Tins::IPv6Address::to_string(void)const " (?to_string@IPv6Address@Tins@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) ipv6_address.obj
    LNK2019	unresolved external symbol _GetIpForwardTable2@8 referenced in function "class std::vector<struct Tins::Utils::Route6Entry,class std::allocator<struct Tins::Utils::Route6Entry> > __cdecl Tins::Utils::route6_entries(void)" (?route6_entries@Utils@Tins@@YA?AV?$vector@URoute6Entry@Utils@Tins@@V?$allocator@URoute6Entry@Utils@Tins@@@std@@@std@@XZ)	routing_utils.obj
    LNK2019	unresolved external symbol _FreeMibTable@4 referenced in function __catch$?route6_entries@Utils@Tins@@YA?AV?$vector@URoute6Entry@Utils@Tins@@V?$allocator@URoute6Entry@Utils@Tins@@@std@@@std@@XZ$0 routing_utils.obj
    LNK1120	4 unresolved externals
    

    Where did I go wrong?


  • Qt Champions 2017

    @ffddrrrttt said in libtins:

    http://libtins.github.io/

    Since errors were in different language, I could not understand the error messages.



  • @dheerendra said in libtins:

    @ffddrrrttt said in libtins:

    http://libtins.github.io/

    Since errors were in different language, I could not understand the error messages.

    Added code


  • Lifetime Qt Champion

    @ffddrrrttt on Windows, its important to compile all libs and apps linking them with the same compiler and same bitness (32/64).

    can you compile the lib yourself?

    Edit: Also, either compile all libs as debug, or all as release.

    I have only glanced over your pro file (I'm on the phone), please check all the paths here.



  • @aha_1980 said in libtins:

    @ffddrrrttt on Windows, its important to compile all libs and apps linking them with the same compiler and same bitness (32/64).

    can you compile the lib yourself?

    Edit: Also, either compile all libs as debug, or all as release.

    I have only glanced over your pro file (I'm on the phone), please check all the paths here.

    I did everything according to this instruction https://ibb.co/X8kDdxb
    Then I opened the file libtins.sln with VS 2017. I compiled the tins Debug Win32 file and got the tins.lib file in the lib / Debug folder.
    The wpcap.lib library was in the folder with WpdPack.
    I downloaded the libraries ws2_32.lib and iphlpapi.lib from the Internet.



  • @ffddrrrttt said in libtins:

    LNK2019 unresolved external symbol _GetIpForwardTable2@8 referenced in function (...)

    Google the symbols in the linker error to see what they are and where they come from, for example GetIpForwardTable2:

    https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getipforwardtable2

    And the documentation says which libraries defines those symbols. You just need to link the required library.



  • @wrosecrans said in libtins:

    @ffddrrrttt said in libtins:

    LNK2019 unresolved external symbol _GetIpForwardTable2@8 referenced in function (...)

    Google the symbols in the linker error to see what they are and where they come from, for example GetIpForwardTable2:

    https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getipforwardtable2

    And the documentation says which libraries defines those symbols. You just need to link the required library.

    I downloaded again IPHlpApi.lib and added again to the project C: /Users/HOME/Desktop/xx/ip/iphlpapi.lib (.pro).. Errors now become 3

    LNK2019 unresolved external symbol __imp__inet_pton@12 referenced in function "private: unsigned int __thiscall Tins::IPv4Address::ip_to_int(char const *)" (?ip_to_int@IPv4Address@Tins@@AAEIPBD@Z) ip_address.obj
    LNK2001	unresolved external symbol __imp__inet_pton@12 ipv6_address.obj
    LNK2019	unresolved external symbol _inet_ntop@16 referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Tins::IPv6Address::to_string(void)const " (?to_string@IPv6Address@Tins@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) ipv6_address.obj
    

    I downloaded again ws2_32.lib (other errors due to this library) and added again to the project C: /Users/HOME/Desktop/xx/ip/ws2_32.lib (.pro). Errors do not decrease.


  • Qt Champions 2019

    @ffddrrrttt Again: did you build the libs using exact same compiler in exact same mode (debug/release) you're using for Qt?



  • This post is deleted!


  • This post is deleted!


  • Solved the problem by downloading ws2_32.lib from another site.



  • @ffddrrrttt glad you solved your issue. Please don't forget to mark your post as such! Thanks.


Log in to reply