首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >c++ libtins生成错误

c++ libtins生成错误
EN

Stack Overflow用户
提问于 2016-11-16 18:03:06
回答 1查看 1K关注 0票数 2

我正在尝试在http://libtins.github.io上构建荔枝包示例。

我遵循了安装说明,并且能够很好地实现#include <tins/tins.h>。现在的问题似乎是实际引用它的功能。当试图构建这个类时:

代码语言:javascript
复制
#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);
}

我知道这个错误:

代码语言:javascript
复制
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,我用-DLIBTINS_ENABLE_CXX11=1启用了c++11支持,运行了ldconfig,并重新启动了VM,同样的错误。

我试着把这个类和g++ main.cpp -o main -ltins联系起来得到这些错误-

代码语言:javascript
复制
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连接起来解决了上述问题,但现在我有以下错误-

代码语言:javascript
复制
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)

我真的不知道我错过了什么。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-16 18:11:37

从错误日志中的undefined reference消息可以看出,您没有将库添加/链接到您的项目。我不知道你的Netbean项目设置,但是如果你使用gcc,你可以看到一个例子这里

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40639152

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档