UObjectLibrary LNK2001 Error

Hey all,

I’ve been scratching my head for a couple of hours at this.

Whenever I create a UObjectLibrary derived class, I get thrown a lot of LNK 2001 errors that I’m not sure how to fix?

The errors:

MyObjectLibrary.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UObjectLibrary::OnAssetRegistryFilesLoaded(void)" (?OnAssetRegistryFilesLoaded@UObjectLibrary@@UEAAXXZ)
MyObjectLibrary.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UObjectLibrary::PostEditChangeProperty(struct FPropertyChangedEvent &)" (?PostEditChangeProperty@UObjectLibrary@@UEAAXAEAUFPropertyChangedEvent@@@Z)
MyObjectLibrary.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UObjectLibrary::PostEditChangeProperty(struct FPropertyChangedEvent &)" (?PostEditChangeProperty@UObjectLibrary@@UEAAXAEAUFPropertyChangedEvent@@@Z)
MyObjectLibrary.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UObjectLibrary::PostLoad(void)" (?PostLoad@UObjectLibrary@@UEAAXXZ)
MyObjectLibrary.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UObjectLibrary::PostLoad(void)" (?PostLoad@UObjectLibrary@@UEAAXXZ)
MyObjectLibrary.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UObjectLibrary::UseWeakReferences(bool)" (?UseWeakReferences@UObjectLibrary@@UEAAX_N@Z)
MyObjectLibrary.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UObjectLibrary::UseWeakReferences(bool)" (?UseWeakReferences@UObjectLibrary@@UEAAX_N@Z)
MyObjectLibrary.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl UObjectLibrary::AddObject(class UObject *)" (?AddObject@UObjectLibrary@@UEAA_NPEAVUObject@@@Z)
MyObjectLibrary.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl UObjectLibrary::AddObject(class UObject *)" (?AddObject@UObjectLibrary@@UEAA_NPEAVUObject@@@Z)
MyObjectLibrary.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl UObjectLibrary::RemoveObject(class UObject *)" (?RemoveObject@UObjectLibrary@@UEAA_NPEAVUObject@@@Z)
MyObjectLibrary.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl UObjectLibrary::RemoveObject(class UObject *)" (?RemoveObject@UObjectLibrary@@UEAA_NPEAVUObject@@@Z)
MyObjectLibrary.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UObjectLibrary::GetAssetDataList(class TArray<struct FAssetData,class TSizedDefaultAllocator<32> > &)" (?GetAssetDataList@UObjectLibrary@@UEAAXAEAV?$TArray@UFAssetData@@V?$TSizedDefaultAllocator@$0CA@@@@@@Z)
MyObjectLibrary.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UObjectLibrary::GetAssetDataList(class TArray<struct FAssetData,class TSizedDefaultAllocator<32> > &)" (?GetAssetDataList@UObjectLibrary@@UEAAXAEAV?$TArray@UFAssetData@@V?$TSizedDefaultAllocator@$0CA@@@@@@Z)
MyObjectLibrary.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UObjectLibrary::ClearLoaded(void)" (?ClearLoaded@UObjectLibrary@@UEAAXXZ)
MyObjectLibrary.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UObjectLibrary::ClearLoaded(void)" (?ClearLoaded@UObjectLibrary@@UEAAXXZ)
MyObjectLibrary.cpp.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl UObjectLibrary::LoadAssetsFromPaths(class TArray<class FString,class TSizedDefaultAllocator<32> > const &)" (?LoadAssetsFromPaths@UObjectLibrary@@UEAAHAEBV?$TArray@VFString@@V?$TSizedDefaultAllocator@$0CA@@@@@@Z)
MyObjectLibrary.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl UObjectLibrary::LoadAssetsFromPaths(class TArray<class FString,class TSizedDefaultAllocator<32> > const &)" (?LoadAssetsFromPaths@UObjectLibrary@@UEAAHAEBV?$TArray@VFString@@V?$TSizedDefaultAllocator@$0CA@@@@@@Z)
MyObjectLibrary.cpp.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl UObjectLibrary::LoadBlueprintsFromPaths(class TArray<class FString,class TSizedDefaultAllocator<32> > const &)" (?LoadBlueprintsFromPaths@UObjectLibrary@@UEAAHAEBV?$TArray@VFString@@V?$TSizedDefaultAllocator@$0CA@@@@@@Z)
MyObjectLibrary.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl UObjectLibrary::LoadBlueprintsFromPaths(class TArray<class FString,class TSizedDefaultAllocator<32> > const &)" (?LoadBlueprintsFromPaths@UObjectLibrary@@UEAAHAEBV?$TArray@VFString@@V?$TSizedDefaultAllocator@$0CA@@@@@@Z)
MyObjectLibrary.cpp.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl UObjectLibrary::LoadAssetDataFromPaths(class TArray<class FString,class TSizedDefaultAllocator<32> > const &,bool)" (?LoadAssetDataFromPaths@UObjectLibrary@@UEAAHAEBV?$TArray@VFString@@V?$TSizedDefaultAllocator@$0CA@@@@@_N@Z)
MyObjectLibrary.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl UObjectLibrary::LoadAssetDataFromPaths(class TArray<class FString,class TSizedDefaultAllocator<32> > const &,bool)" (?LoadAssetDataFromPaths@UObjectLibrary@@UEAAHAEBV?$TArray@VFString@@V?$TSizedDefaultAllocator@$0CA@@@@@_N@Z)
MyObjectLibrary.cpp.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl UObjectLibrary::LoadBlueprintAssetDataFromPaths(class TArray<class FString,class TSizedDefaultAllocator<32> > const &,bool)" (?LoadBlueprintAssetDataFromPaths@UObjectLibrary@@UEAAHAEBV?$TArray@VFString@@V?$TSizedDefaultAllocator@$0CA@@@@@_N@Z)
MyObjectLibrary.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl UObjectLibrary::LoadBlueprintAssetDataFromPaths(class TArray<class FString,class TSizedDefaultAllocator<32> > const &,bool)" (?LoadBlueprintAssetDataFromPaths@UObjectLibrary@@UEAAHAEBV?$TArray@VFString@@V?$TSizedDefaultAllocator@$0CA@@@@@_N@Z)
MyObjectLibrary.cpp.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl UObjectLibrary::LoadAssetsFromAssetData(void)" (?LoadAssetsFromAssetData@UObjectLibrary@@UEAAHXZ)
MyObjectLibrary.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl UObjectLibrary::LoadAssetsFromAssetData(void)" (?LoadAssetsFromAssetData@UObjectLibrary@@UEAAHXZ)
MyObjectLibrary.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UObjectLibrary::OnAssetRegistryFilesLoaded(void)" (?OnAssetRegistryFilesLoaded@UObjectLibrary@@UEAAXXZ)

The Code:

//.h
#pragma once

#include "CoreMinimal.h"
#include "Engine/ObjectLibrary.h"
#include "UObject/ObjectMacros.h"
#include "UObject/Object.h"
#include "AssetData.h"
#include "MyObjectLibrary.generated.h"

UCLASS()
class TEST_API UMyObjectLibrary : public UObjectLibrary
{
	GENERATED_BODY()

public:
	UMyObjectLibrary(const FObjectInitializer& ObjectInitializer);
	
};

//.cpp

#include "MyObjectLibrary.h"

UMyObjectLibrary::UMyObjectLibrary(const FObjectInitializer& ObjectInitializer)
{

}

Any help would be appreciated.

On a side note, looking online, there’s not a whole lot of tutorials or documentation of Object Libraries, why would that be?

1 Like

Have you tried re-generating your project files? It could be an issue with the generated file.

1 Like

I have a few times, unfortunately no luck.

I’ve given up on object library for now and looked to load objects in another way.

Only comment I’ll make for others’ reference is that creating a library through the object’s library function, as in the Documentation, seemed to work better:

if (!ObjectLibrary)
{
       ObjectLibrary = UObjectLibrary::CreateLibrary(BaseClass::StaticClass(), false, GIsEditor);
       ObjectLibrary->AddToRoot();
}
ObjectLibrary->LoadAssetDataFromPath(TEXT("/Game/PathWithAllObjectsOfSameType");
if (bFullyLoad)
{
       ObjectLibrary->LoadAssetsFromAssetData();
}

Asynchronous Asset Loading

1 Like

UObjectLibrary is MinimalAPI so unfortunately you can’t derive from it. This is presumably by design

3 Likes

Wait, really? you can’t derive from MinimalAPI classes?

I don’t think so no, the class’ methods aren’t exported from its module so you get all these linker errors (the linker can’t find definitions for the methods). It’s fine to derive from MinimalAPI classes within the same module. It looks like you can use UObjectLibrary objects in other modules - that’s probably because all of the relevant methods are either virtual, so the function addresses don’t need to be known at compile time, or inline, where the implementation is just in the header.

1 Like