我想从Oment ++中inet的UdpBasicApp派生一个类。确实,我想编写自己的应用程序。我编写了以下代码,但是在编译项目时出现错误。要正确编译该项目,该怎么办?
Creating executable: out/clang-release//Manet_1.1.exe
out/clang-release//MyApp.o:(.rdata[_ZTIN4inet11UdpBasicAppE]+0x10): undefined reference to `typeinfo for inet::ApplicationBase'
out/clang-release//MyApp.o:(.rdata[_ZTV5MyApp]+0x640): undefined reference to `non-virtual thunk to inet::OperationalBase::handleOperationStage(inet::LifecycleOperation*, int, inet::IDoneCallback*)'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:101: out/clang-release//Manet_1.1.exe] Error 1
MyApp.h
#include "../../inet/src/inet/applications/udpapp/UdpBasicApp.h"
using namespace inet;
class MyApp : public UdpBasicApp
{
public:
};
MyApp.c
#include "MyApp.h"
Define_Module(MyApp);
MyApp.net
import inet.applications.udpapp.UdpBasicApp;
simple MyApp extends UdpBasicApp
{
@class(MyApp);
}
答案 0 :(得分:0)
很显然,您正在自己的项目中工作,该项目无法正确地与INET模型链接。您必须在自己的项目的项目属性对话框中选择INET作为项目引用。这样会将INET的include文件夹添加到include路径,因此您只需要(正确地)只写
#include "inet/applications/udpapp/UdpBasicApp.h"
代替
#include "../../inet/src/inet/applications/udpapp/UdpBasicApp.h"
并且还将修改链接器命令行以正确地与INET共享库链接。