Hello everyone,
I’m trying to use an external library on Unreal but I’m facing some issues when compiling. I have noticed the problem is happening with methods defined as virtual.
1>CommandRepository.gen.cpp.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl EventObserver<class FString>::~EventObserver<class FString>(void)" (??1?$EventObserver@VFString@@@@UEAA@XZ) referenced in function "public: virtual void * __cdecl EventObserver<class FString>::`scalar deleting destructor'(unsigned int)" (??_G?$EventObserver@VFString@@@@UEAAPEAXI@Z)
1>CommandRepository.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl EventObserver::Unsubscribe(class std::basic_string,class std::allocator >,class ISubscription *)" (?Unsubscribe@?$EventObserver@VFString@@@@UEAAXV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@PEAV?$ISubscription@VFString@@@@@Z)
1>CommandRepository.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl EventObserver::Complete(void)" (?Complete@?$EventObserver@VFString@@@@UEAAXXZ)
1>CommandRepository.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl EventObserver::Fail(void)" (?Fail@?$EventObserver@VFString@@@@UEAAXXZ)
I followed that tutorial to configure the library Wiki tutorial and my setup is the following:
Commands/ThirdParty/ObserverLibrary/Includes/*.h
Commands/ThirdParty/ObserverLibrary/Libraries/ObserverLibrary.lib
// Commands.build.cs
using System.IO;
using UnrealBuildTool;
public class Commands : ModuleRules
{
private string ModulePath {get { return ModuleDirectory; }}
private string ThirdPartyPath {get { return Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/")); }}
public Commands(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
PrivateDependencyModuleNames.AddRange(new string[] { });
LoadObserverLibrary();
}
public void LoadObserverLibrary()
{
string LibrariesPath = Path.Combine(ThirdPartyPath, "ObserverLibrary", "Libraries");
PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "ObserverLibrary", "Includes"));
PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "ObserverLibrary.lib"));
}
}
Class using the library
// CommandRepository.h
#include <ObserverLibrary/Includes/EventObserver.h>
#include "CommandRepository.generated.h"
UCLASS()
class COMMANDS_API UCommandRepository : public UObject
{
GENERATED_BODY()
private:
EventObserver<FString> Observer;
};
EventObserver header:
#include <deque>
#include <map>
#include "Interfaces.h"
/**
* Main Class
*/
template<class Param>
class EventObserver : public IEventObserver<Param>
{
public:
virtual ~EventObserver();
template<class T>
std::weak_ptr<ISubscription<Param>> Subscribe(std::basic_string<TCHAR> EventName, T* Instance, void (T::*MethodPointer)(Param*));
void Next(std::basic_string<TCHAR> EventName, Param* eventParam);
virtual void Unsubscribe(std::basic_string<TCHAR> EventName, ISubscription<Param>* Subscription) override;
virtual void Complete() override;
virtual void Fail() override;
};
Could anyone give me a feedback and clarify what is missing here?