How can I resolve an Unresolved Externals error when referencing classes in another module?

I have created a simple module based off the Paper2DJsonImporter module.

I’ve added my main module to the build file like this…

	PrivateDependencyModuleNames.AddRange(
			new string[] {
				"Core",
				"CoreUObject",	
			    "Engine",			
	            "Elemental", //<---
				"UnrealEd"
			});

In my JsonImporterFactory.cpp file I…

#include "ElementalClasses.h"

This works as expected and I can at least reference classes from my main module in code. However, when I try and build, it gives me this error:

Error 1 error LNK2019: unresolved external symbol “private: static class UClass * __cdecl UElementalGestureListener::GetPrivateStaticClass(wchar_t const *)” (?GetPrivateStaticClass@UElementalGestureListener@@CAPEAVUClass@@PEB_W@Z) referenced in function “class UElementalGestureListener * __cdecl Cast(class UObject *)” (??$Cast@VUElementalGestureListener@@@@YAPEAVUElementalGestureListener@@PEAVUObject@@@Z) D:\Elemental_UE4\Elemental\Intermediate\ProjectFiles\ElementalJsonImporterFactory.cpp.obj Elemental

I’ve tried all sorts of ways of referencing the object in question (UElementalGestureListener). Moving files from private/classes folders etc., adding…

OutExtraModuleNames.Add("ElementalJsonImporter");

To my game target as well as the editor target. Editing the DefaultEngine as mentioned here:

But nothing seems to work and I’m totally out of ideas now!

Any help would be very much appreciated.

Thanks!

I believe your issue is that the class needs to be flagged for export so that other modules can link to your symbols.

Depending on your needs you can do this by adding MinimalAPI to the UCLASS macro. This just exports some key auto-generated functions (such as GetPrivateStaticClass) and any functions/members that you explicitly tag using the [MODULENAME]_API tag (so if your module is called Elemental it is probably ELEMENTAL_API).

Alternatively you can mark the entire class for export such that all public (and protected if you are inheriting from it) members and functions are available. You do this by again using the _API tag on the class, so your class definition ends up looking something like class ELEMENTAL_API UElementalGestureListener : public UObject (or what have you).

Thanks for replying.

Adding ELEMENTAL_API seems to have fixed the build error. However my module doesn’t appear to be loaded in the editor.

It’s a custom (json) file format importer. I had this working previously but wanted to move it to a module instead of being in the main game module. (So I know it works).

When I try to import it doesn’t give me the option for json (which it previously did) and the only module listed in Developer Tools>Modules is the main module (Elemental).

To confirm, I have this in my Editor Target file:

OutExtraModuleNames.Add("ElementalJsonImporter");

If anyone is interested. I Solved the issue of the module not appearing to work by making it a plugin.

Hello, DannRees. Would you mind providing some more information about how you were able to solve the issue you were having? There may be others with a similar issue who would benefit from having more information available.

Have a great day.

As requested by . Here’s a little more info on the problem I had and how I solved it.

Firstly I created a custom file importer in my main module. It all worked great but thought I should probably put it in the separate module.

So after moving it to another module, I needed to reference a class from my main game module. And even though I imported the main game module without an issue and there were no intellisense errors. When it came to building it would fail with “Unresolved External Symbols”.

To fix this (as suggested by ). I added _API to the class I was trying to access. So it looked like this:

class ELEMENTAL_API UElementalGestureListener : public UObject 

instead of this

class UElementalGestureListener : public UObject 

It would then build without errors. Splendid! However, the module didn’t seem to appear in the editor as it did when it was in the main module (no option to import my file format).
I fixed this by making the module a plugin instead by copying the module folder & contents to a new Plugins folder in my project root directory and created a uplugin file to accompany it.

I’m not sure on the official way of creating these uplugin files but I copied one from the experimental folder in the engines plugins and changed it.

Then they all lived happily ever after.

The End x

1 Like