x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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@@XZ) 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.

Product Version: UE 4.19
Tags:
more ▼

asked Nov 28 '17 at 11:59 PM in C++ Programming

avatar image

Mowglica
36 1 2 5

avatar image Alex-V Nov 29 '17 at 02:49 PM

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

avatar image Mowglica Nov 30 '17 at 01:13 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Nov 30 '17 at 07:34 AM

avatar image

Alex-V
21 1 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Jan 09 '19 at 08:35 PM

avatar image

RajZoox
61 1 9 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question