OMNeT++ 链接 INET 的问题 [英] OMNeT++ issue with linking INET
问题描述
在构建我的新 OMNeT++
项目期间,我遇到了以下错误:
During the build of my new OMNeT++
project I have encountered following error:
out/clang-debug//myUdp.o:(.rdata[_ZTI5myUdp]+0x10): 未定义对 'typeinfo for inet::ApplicationBase' 的引用
我已经配置了 INET
引用(项目myUdp" -> 属性 -> 项目引用 -> inet 复选框被选中)
I have already configured INET
reference (Project "myUdp" -> Properties -> Project reference -> inet checkbox selected)
这是 INET Makemake 配置: 目标选项卡和 编译标签
这是我的项目(myUdp)的Makemake配置: 编译标签 和链接标签
和 C++ 代码:
MyUdp.cc
#include <inet/applications/udpapp/UDPBasicApp.h>
class myUdp: public inet::UDPBasicApp {
};
Define_Module(myUdp);
MyUdp.ned
import inet.applications.udpapp.UDPBasicApp;
simple myUdp extends UDPBasicApp {
@class(myUdp);
}
有人能帮我解决这个错误吗?
Can somebody help me to solve this error?
推荐答案
那可能是因为UDPBasicApp的方法被定义为virtual
.
That is probably because UDPBasicApp's methods are defined as virtual
.
比较来自 http://gcc 的 GCC 信息模糊链接".gnu.org/onlinedocs/gcc/Vague-Linkage.html,例如这部分:
Compare the GCC infos on "vague linking" from http://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html, for example this part:
type_info
对象
C++ 需要写出有关类型的信息,以便实现dynamic_cast
、typeid
和异常处理.为了多态类(带有 virtual
函数的类),type_info
对象与 vtable 一起写出,以便 dynamic_cast
可以在运行时确定类对象的动态类型.对所有人其他类型,我们在使用时写出type_info
对象:当将 typeid
应用于表达式、抛出对象或引用到 catch 子句或异常规范中的类型.
C++ requires information about types to be written out in order to
implement dynamic_cast
, typeid
and exception handling. For
polymorphic classes (classes with virtual
functions), the type_info
object is written out along with the vtable so that dynamic_cast
can
determine the dynamic type of a class object at run time. For all
other types, we write out the type_info
object when it is used: when
applying typeid
to an expression, throwing an object, or referring
to a type in a catch clause or exception specification.
您需要为基类 (UDPBasicApp) 中的虚函数提供定义或将它们声明为纯函数,因为编译器(在您的情况下为 GCC 或 Clang)正在尝试为翻译单元确定正确的方法(然后创建 vtable 和 typeinfo 对象的位置)并且它显然无法正确确定它.
You would need to provide either a definition for the virtual functions in the base class (UDPBasicApp) or declare them pure, because the compiler (GCC or Clang in your case) is trying to determine the right method for the translation unit (where the vtable and typeinfo objects are then created) and it cannot determine it correctly apparently.
这篇关于OMNeT++ 链接 INET 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!