2016-11-16 56 views
1

我正在試圖在http://libtins.github.io上的litbins生成數據包示例。C++ libtins生成錯誤

我按照安裝說明,能夠#include <tins/tins.h>就好。現在的問題似乎是在實際引用它的功能。當試圖建立這個類:

#include <tins/tins.h> 
#include <cassert> 
#include <iostream> 
#include <string> 

using namespace Tins; 
int main() { 

    NetworkInterface iface = NetworkInterface::default_interface(); 

    NetworkInterface::Info info = iface.addresses(); 

    EthernetII eth("77:22:33:11:ad:ad", info.hw_addr); 

    eth /= IP("localhost", info.ip_addr); 

    eth /= TCP(13, 15); 

    eth /= RawPDU("I'm a payload!"); 

    PacketSender sender; 

    sender.send(eth, iface); 
} 

我得到這個錯誤:

cd '/home/oisin/NetBeansProjects/TCPPacket' 
/usr/bin/gmake -f Makefile CONF=Debug 
"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf 
gmake[1]: Entering directory '/home/oisin/NetBeansProjects/TCPPacket' 
"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/tcppacket 
gmake[2]: Entering directory '/home/oisin/NetBeansProjects/TCPPacket' 
mkdir -p build/Debug/GNU-Linux 
rm -f "build/Debug/GNU-Linux/main.o.d" 
g++ -c -g -std=c++11 -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp 
mkdir -p dist/Debug/GNU-Linux 
g++  -o dist/Debug/GNU-Linux/tcppacket build/Debug/GNU-Linux/main.o 
build/Debug/GNU-Linux/main.o: In function `main': 
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:26: undefined reference to `Tins::NetworkInterface::default_interface()' 
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:28: undefined reference to `Tins::NetworkInterface::addresses() const' 
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:30: undefined reference to `Tins::EthernetII::EthernetII(Tins::HWAddress<6ul, unsigned char> const&, Tins::HWAddress<6ul, unsigned char> const&)' 
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:32: undefined reference to `Tins::IPv4Address::IPv4Address(char const*)' 
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:32: undefined reference to `Tins::IP::IP(Tins::IPv4Address, Tins::IPv4Address)' 
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:34: undefined reference to `Tins::TCP::TCP(unsigned short, unsigned short)' 
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:36: undefined reference to `Tins::RawPDU::RawPDU(std::string const&)' 
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:38: undefined reference to `Tins::PacketSender::DEFAULT_TIMEOUT' 
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:38: undefined reference to `Tins::NetworkInterface::NetworkInterface()' 
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:38: undefined reference to `Tins::PacketSender::PacketSender(Tins::NetworkInterface const&, unsigned int, unsigned int)' 
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:40: undefined reference to `Tins::PacketSender::send(Tins::PDU&, Tins::NetworkInterface const&)' 
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:38: undefined reference to `Tins::PacketSender::~PacketSender()' 
/home/oisin/NetBeansProjects/TCPPacket/main.cpp:38: undefined reference to `Tins::PacketSender::~PacketSender()' 
build/Debug/GNU-Linux/main.o: In function `Tins::EthernetII& Tins::operator/=<Tins::EthernetII>(Tins::EthernetII&, Tins::PDU const&)': 
/usr/local/include/tins/pdu.h:537: undefined reference to `Tins::PDU::inner_pdu(Tins::PDU*)' 
build/Debug/GNU-Linux/main.o: In function `Tins::EthernetII::~EthernetII()': 
/usr/local/include/tins/ethernetII.h:46: undefined reference to `vtable for Tins::EthernetII' 
/usr/local/include/tins/ethernetII.h:46: undefined reference to `Tins::PDU::~PDU()' 
build/Debug/GNU-Linux/main.o: In function `Tins::IP::~IP()': 
/usr/local/include/tins/ip.h:64: undefined reference to `vtable for Tins::IP' 
/usr/local/include/tins/ip.h:64: undefined reference to `Tins::PDU::~PDU()' 
build/Debug/GNU-Linux/main.o: In function `Tins::TCP::~TCP()': 
/usr/local/include/tins/tcp.h:79: undefined reference to `vtable for Tins::TCP' 
/usr/local/include/tins/tcp.h:79: undefined reference to `Tins::PDU::~PDU()' 
build/Debug/GNU-Linux/main.o: In function `Tins::RawPDU::~RawPDU()': 
/usr/local/include/tins/rawpdu.h:64: undefined reference to `vtable for Tins::RawPDU' 
/usr/local/include/tins/rawpdu.h:64: undefined reference to `Tins::PDU::~PDU()' 
collect2: error: ld returned 1 exit status 
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/GNU-Linux/tcppacket' failed 
gmake[2]: *** [dist/Debug/GNU-Linux/tcppacket] Error 1 
gmake[2]: Leaving directory '/home/oisin/NetBeansProjects/TCPPacket' 
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed 
gmake[1]: *** [.build-conf] Error 2 
gmake[1]: Leaving directory '/home/oisin/NetBeansProjects/TCPPacket' 
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed 
gmake: *** [.build-impl] Error 2 

BUILD FAILED (exit value 2, total time: 1s) 

NetBeans是使用C++ 11,我已經啓用C++ 11的支持與-DLIBTINS_ENABLE_CXX11=1,我已經運行ldconfig並重新啓動虛擬機,出現相同的錯誤。

我已經試過類g++ main.cpp -o main -ltins鏈接到得到這些錯誤 -

In file included from /usr/local/include/tins/tins.h:60:0, 
       from main.cpp:14: 
/usr/local/include/tins/crypto.h:297:13: error: ‘function’ in namespace ‘std’ does not name a type 
    typedef std::function<void(const std::string&, 
      ^
/usr/local/include/tins/crypto.h:308:13: error: ‘function’ in namespace ‘std’ does not name a type 
    typedef std::function<void(const std::string&, 
      ^
/usr/local/include/tins/crypto.h:401:44: error: ‘handshake_captured_callback_type’ does not name a type 
    void handshake_captured_callback(const handshake_captured_callback_type& callback); 
              ^
/usr/local/include/tins/crypto.h:412:34: error: ‘ap_found_callback_type’ does not name a type 
    void ap_found_callback(const ap_found_callback_type& callback); 
           ^
/usr/local/include/tins/crypto.h:445:9: error: ‘handshake_captured_callback_type’ does not name a type 
     handshake_captured_callback_type handshake_captured_callback_; 
     ^
/usr/local/include/tins/crypto.h:446:9: error: ‘ap_found_callback_type’ does not name a type 
     ap_found_callback_type ap_found_callback_; 
     ^

幫助表示讚賞。

編輯

從dvnguyen的回答繼下方,連接我main.cppg++ app.cpp -o app -ltins -std=c++11解決了上述問題,但現在我留下了以下錯誤 -

cd '/home/oisin/NetBeansProjects/TCPPacket' 
/usr/bin/gmake -f Makefile CONF=Debug 
"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf 
gmake[1]: Entering directory '/home/oisin/NetBeansProjects/TCPPacket' 
"/usr/bin/gmake" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/tcppacket 
gmake[2]: Entering directory '/home/oisin/NetBeansProjects/TCPPacket' 
mkdir -p build/Debug/GNU-Linux 
rm -f "build/Debug/GNU-Linux/main.o.d" 
g++ -c -g -std=c++11 -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp 
mkdir -p dist/Debug/GNU-Linux 
g++  -o dist/Debug/GNU-Linux/tcppacket build/Debug/GNU-Linux/main.o -lmain 
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lmain 
collect2: error: ld returned 1 exit status 
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/GNU-Linux/tcppacket' failed 
gmake[2]: *** [dist/Debug/GNU-Linux/tcppacket] Error 1 
gmake[2]: Leaving directory '/home/oisin/NetBeansProjects/TCPPacket' 
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed 
gmake[1]: *** [.build-conf] Error 2 
gmake[1]: Leaving directory '/home/oisin/NetBeansProjects/TCPPacket' 
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed 
gmake: *** [.build-impl] Error 2 

BUILD FAILED (exit value 2, total time: 2s) 

我真的爲無能我失去了什麼。

回答

1

從錯誤日誌中的undefined reference消息我可以告訴你沒有添加/鏈接到您的項目的lib。我不知道你的Netbean項目設置,但如果你使用GCC,你可以看到一個例子here

g++ app.cpp -o app -ltins -std=c++11

+0

感謝您的輸入,我已經嘗試過這樣 - 用日誌中看到更新的問題。 – xeon48

+0

這可能是由C++ 11類型引起的。我認爲這應該工作: – dvnguyen

+0

g ++ app.cpp -o app -ltins -std = C++ 11 – dvnguyen