子类化 NullFederateAmbassador 时出现链接错误

问题描述

我正在尝试用 C++ 编写我自己的 RTI 实现。

我导入了 IEEE 1516 HLA 演进 API,并创建了 NullFederateAmbassador 的子类。

我收到 60 多个未解决的外部符号错误,附在下面。

我唯一写过的 C++ 是这样的:

#include "pch.h"
#include "RTI/RTI1516.h"
#include "RTI/NullFederateAmbassador.h"

using namespace rti1516e;

class NullFederateAmbassadorChild : public NullFederateAmbassador {

};

void Connect() {
    NullFederateAmbassadorChild c;
}

代码在 IntelliSense 中连接良好。我的 pch.h 里面什么都没有。 RTI 文件与来自 IEEE 的原始 RTI 文件完全相同。

1>CBRTILibrary.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl rti1516e::NullFederateAmbassador::NullFederateAmbassador(void)" (__imp_??0NullFederateAmbassador@rti1516e@@QEAA@XZ) referenced in function "public: __cdecl NullFederateAmbassadorChild::NullFederateAmbassadorChild(void)" (??0NullFederateAmbassadorChild@@QEAA@XZ)
1>CBRTILibrary.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl rti1516e::NullFederateAmbassador::~NullFederateAmbassador(void)" (__imp_??1NullFederateAmbassador@rti1516e@@UEAA@XZ) referenced in function "public: virtual __cdecl NullFederateAmbassadorChild::~NullFederateAmbassadorChild(void)" (??1NullFederateAmbassadorChild@@UEAA@XZ)
1>CBRTILibrary.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl rti1516e::NullFederateAmbassador::announceSynchronizationPoint(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &,class rti1516e::VariableLengthData const &)" (?announceSynchronizationPoint@NullFederateAmbassador@rti1516e@@UEAAXAEBV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@AEBVVariableLengthData@2@@Z)
1>CBRTILibrary.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl rti1516e::NullFederateAmbassador::attributeIsNotOwned(class rti1516e::ObjectInstanceHandle,class rti1516e::AttributeHandle)" (?attributeIsNotOwned@NullFederateAmbassador@rti1516e@@UEAAXVObjectInstanceHandle@2@VAttributeHandle@2@@Z)
1>CBRTILibrary.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl rti1516e::NullFederateAmbassador::attributeIsOwnedByRTI(class rti1516e::ObjectInstanceHandle,class rti1516e::AttributeHandle)" (?attributeIsOwnedByRTI@NullFederateAmbassador@rti1516e@@UEAAXVObjectInstanceHandle@2@VAttributeHandle@2@@Z)
1>CBRTILibrary.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl rti1516e::NullFederateAmbassador::attributeOwnershipAcquisitionNotification(class rti1516e::ObjectInstanceHandle,class std::set<class rti1516e::AttributeHandle,struct std::less<class rti1516e::AttributeHandle>,class std::allocator<class rti1516e::AttributeHandle> > const &,class rti1516e::VariableLengthData const &)" (?attributeOwnershipAcquisitionNotification@NullFederateAmbassador@rti1516e@@UEAAXVObjectInstanceHandle@2@AEBV?$set@VAttributeHandle@rti1516e@@U?$less@VAttributeHandle@rti1516e@@@std@@V?$allocator@VAttributeHandle@rti1516e@@@4@@std@@AEBVVariableLengthData@2@@Z)
1>CBRTILibrary.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl rti1516e::NullFederateAmbassador::attributeOwnershipUnavailable(class rti1516e::ObjectInstanceHandle,class std::allocator<class rti1516e::AttributeHandle> > const &)" (?attributeOwnershipUnavailable@NullFederateAmbassador@rti1516e@@UEAAXVObjectInstanceHandle@2@AEBV?$set@VAttributeHandle@rti1516e@@U?$less@VAttributeHandle@rti1516e@@@std@@V?$allocator@VAttributeHandle@rti1516e@@@4@@std@@@Z)
1>CBRTILibrary.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl rti1516e::NullFederateAmbassador::attributesInScope(class rti1516e::ObjectInstanceHandle,class std::allocator<class rti1516e::AttributeHandle> > const &)" (?attributesInScope@NullFederateAmbassador@rti1516e@@UEAAXVObjectInstanceHandle@2@AEBV?$set@VAttributeHandle@rti1516e@@U?$less@VAttributeHandle@rti1516e@@@std@@V?$allocator@VAttributeHandle@rti1516e@@@4@@std@@@Z)
1>CBRTILibrary.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl rti1516e::NullFederateAmbassador::attributesOutOfScope(class rti1516e::ObjectInstanceHandle,class std::allocator<class rti1516e::AttributeHandle> > const &)" (?attributesOutOfScope@NullFederateAmbassador@rti1516e@@UEAAXVObjectInstanceHandle@2@AEBV?$set@VAttributeHandle@rti1516e@@U?$less@VAttributeHandle@rti1516e@@@std@@V?$allocator@VAttributeHandle@rti1516e@@@4@@std@@@Z)
1>CBRTILibrary.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl rti1516e::NullFederateAmbassador::confirmAttributeOwnershipAcquisitionCancellation(class rti1516e::ObjectInstanceHandle,class std::allocator<class rti1516e::AttributeHandle> > const &)" (?confirmAttributeOwnershipAcquisitionCancellation@NullFederateAmbassador@rti1516e@@UEAAXVObjectInstanceHandle@2@AEBV?$set@VAttributeHandle@rti1516e@@U?$less@VAttributeHandle@rti1516e@@@std@@V?$allocator@VAttributeHandle@rti1516e@@@4@@std@@@Z)
1>CBRTILibrary.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl rti1516e::NullFederateAmbassador::confirmAttributeTransportationTypeChange(class rti1516e::ObjectInstanceHandle,class std::allocator<class rti1516e::AttributeHandle> >,enum rti1516e::TransportationType)" (?confirmAttributeTransportationTypeChange@NullFederateAmbassador@rti1516e@@UEAAXVObjectInstanceHandle@2@V?$set@VAttributeHandle@rti1516e@@U?$less@VAttributeHandle@rti1516e@@@std@@V?$allocator@VAttributeHandle@rti1516e@@@4@@std@@W4TransportationType@2@@Z)
1>CBRTILibrary.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl rti1516e::NullFederateAmbassador::confirmInteractionTransportationTypeChange(class rti1516e::InteractionClassHandle,enum rti1516e::TransportationType)" (?confirmInteractionTransportationTypeChange@NullFederateAmbassador@rti1516e@@UEAAXVInteractionClassHandle@2@W4TransportationType@2@@Z)
1>CBRTILibrary.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl rti1516e::NullFederateAmbassador::connectionLost(class std::basic_string<wchar_t,class std::allocator<wchar_t> > const &)" (?connectionLost@NullFederateAmbassador@rti1516e@@UEAAXAEBV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z)
1>CBRTILibrary.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl rti1516e::NullFederateAmbassador::discoverObjectInstance(class rti1516e::ObjectInstanceHandle,class rti1516e::ObjectClassHandle,class std::basic_string<wchar_t,class std::allocator<wchar_t> > const &)" (?discoverObjectInstance@NullFederateAmbassador@rti1516e@@UEAAXVObjectInstanceHandle@2@VObjectClassHandle@2@AEBV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z)
1>CBRTILibrary.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl rti1516e::NullFederateAmbassador::discoverObjectInstance(class rti1516e::ObjectInstanceHandle,class rti1516e::FederateHandle)" (?discoverObjectInstance@NullFederateAmbassador@rti1516e@@UEAAXVObjectInstanceHandle@2@VObjectClassHandle@2@AEBV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@VFederateHandle@2@@Z)
1>CBRTILibrary.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl rti1516e::NullFederateAmbassador::federationNotRestored(enum rti1516e::RestoreFailureReason)" (?federationNotRestored@NullFederateAmbassador@rti1516e@@UEAAXW4RestoreFailureReason@2@@Z)
1>mainRti.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl  . . . . . . . . etc

1>C:\Dev\x64\Debug\myRTI.dll : Fatal error LNK1120: 62 unresolved externals

解决方法

IEEE HLA 1516-2010(AKA HLA 1516 Evolved)只是 API 的定义。开发人员可以创建具有实际功能的 RTI。有几个商业 RTI 以及一些 FOSS。我知道 Pitch 和 MaK 出售实施 1516-2010 的那些。最流行的开源实现是 Portico (https://porticoproject.org/)。

一旦您有了 RTI(或者自己编写,如果您愿意的话),您需要编译联邦并将其链接到 RTI 提供的库。