GetPrivateStaticClass() Unresolved External between Modules

I can’t seem to call the “StaticClass” method on classes declared in other modules.

In IndependentModule, I declare ATestActor and ATestActor2:

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "TestClass.generated.h"

UCLASS()
class INDEPENDENTMODULE_API ATestActor : public AActor{

	GENERATED_BODY()

public:
};

UCLASS()
class INDEPENDENTMODULE_API ATestActor2 : public AActor {

	GENERATED_BODY()

public:
};

In DependentModule, I add “IndependentModule” to the Public/PrivateDependency list.
I then try to access the “StaticClass” methods of each class:

#include "IndependentModule/Public/TestClass.h"

void UDependentComponent::TestFunction()
{
	UClass* Class = AActor::StaticClass();
	UClass* Class2 = ATestActor::StaticClass();
	UClass* Class3 = ATestActor2::StaticClass();
}

I get the following error: unresolved external symbol “__declspec(dllimport) private: static class UClass * __cdecl ATestActor2::GetPrivateStaticClass(void)” (_imp?GetPrivateStaticClass@ATestActor2@@CAPEAVUClass@@anonymous_user_9674a66c) referenced in function “public: void __cdecl UDependentComponent::TestFunction(void)” (?TestFunction@UDependentComponent@@QEAAXXZ)

I don’t understand why this is failing on ATestActor2, but working on ATestActor. Additionally, if I change ATestActor to any other name, it fails. I have exposed the classes via the _API. The module is added to the appropriate Dependency list(s). What am I missing?

UPDATE: Several months later, I ran into a similar problem. After some testing in different contexts, the following conclusions are apparent:

  • Adding SomeNewMethod to a class in IndependentModule and implementing that method in the same header file creates no linker issues. DependentModule can call the method with no problems.
  • Adding SomeNewMethod to a class in IndependentModule and implementing that method in the appropriate source file creates linker issues. DependentModule cannot call the method. The only fix is to “Rebuild Solution/Project” (or delete Intermediate/Binaries, as detailed in comments), which takes much longer than a normal iterative “Build”.

Hence, the follow-up question is why? Is this aberrant behavior, caused by some missed lines/files somewhere? Otherwise, if this is expected behavior when linking updated game modules, I would like to know that, so that I can structure development to minimize lengthy Rebuilds.

3 Likes

Got the same. Can’t use classes declared in some shared module. API macro is correct - get precise link error.

I managed to resolve it for the time being, by deleting the Intermediate folder, regenerating project files and compiling.

I had renamed modules/files/classes a few times, and it seems that folders by the old names (i.e. “Independent1, Dependent2, Independent3”) were still showing up in the Intermediate folder. I think that’s where the .generated.h. files come from, and there must have been duplicates from outdated modules screwing things up. That’s my best guess anyways.

I’ll leave the answer open for the time being, in case someone from Epic wants to provide a more coherent/knowledgeable answer.

Worked for me.

  1. Close MSVS
  2. Delete “YourProjectName/Intermediate” folder
  3. Regenerate C++ solution(Right click on uproject file - generate project files)
  4. Open MSVS
  5. Build Project

For me, the reason of issue was that old object files were in the “Intermediate” folder.

I faced the same issue, but the fix to my problem was to export the class.

For example in your case I forgot to add INDEPENDENTMODULE_API to the class

14 Likes

This should be accepted as the solution. The other solutions are just nonsense.

1 Like