4.8 Json Error - unresolved external symbol

I’ve recently upgraded to 4.8 (promoted branch) and for some reason I’m getting linker errors when trying to use JSON:

E.g. in my GameMode constructor:

TSharedPtr<FJsonObject> json;

// Adding the following line results in a compile error
json = MakeShareable(new FJsonObject);

The error is about an unresolved external symbol:

Error 1 error LNK2019: unresolved external symbol “__declspec(dllimport) public: __cdecl FJsonObject::FJsonObject(void)” (_imp??0FJsonObject@@QEAA@XZ) referenced in function “private: __cdecl APWNGameGameMode::APWNGameGameMode(class FObjectInitializer const &)” (??0APWNGameGameMode@@AEAA@AEBVFObjectInitializer@@@Z) E:\UE4\PWNGame\Intermediate\ProjectFiles\PWNGameGameMode.cpp.obj PWNGame

I’ve tried adding includes for both Json.h and JsonObject.h as well the Json Modules in my build file:

public PWNGame(TargetInfo Target)
{
        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Json", "JsonUtilities" });
	PrivateDependencyModuleNames.AddRange(new string[] {  });     
}

but nothing seems to work.

Also, I’ve checked in engine files like Source/Developer/SessionFrontend/Private/Widgets/Console/SSessionConsoleShortcutWindow.cpp and this is exactly the way Json objects are created.

I would greatly appreciate some help on this one.

Thanks!

These linker errors indicate that you’re using code declared somewhere (usually in a header file) but not defined anywhere (usually in a library i.e. unreal engine module). So I would think the only two possibilities are that you are somehow including outdated header files or you’re not linking to the right modules.

Are you using the default directory structure for your project?

Hi Lojo,

Thanks very much for the response and the explanation (I’m still quite a noob with C++, so it helps a lot). I’m listing the steps I took below for clarity:

  • Checked out the latest version of the “promoted” branch from Github (i.e. fetch and reset --hard to be a perfect copy of upstream)
  • Ran setup.bat to download the latest dependencies
  • Generated the Visual Studio .sln file
  • Rebuilt the engine
  • Ran the engine executable
  • Created a new basic code C++ project
  • Added some classes (using default location) like MyPlayerController, MyPlayerCharacter etc.
  • Added the PublicDependency module as stated in the original post
  • In my GameMode class’ constructor added code as in original post, as well as #include “JsonObject.h” and “Json.h” - I’ve tried without these as well.

Do you think I might need to delete my whole Unreal Engine folder and start from scratch?

Thanks!

Unfortunately, I don’t have much experience with UE4 yet (just C++ experience) and have even less experience building the engine from scratch. I was just going through the questions and trying to add helpful input where I could.

Best of luck! I’m sure someone from Unreal would have a decent idea.

Sure, no worries - thanks for the effort.

I’ve found the solution from joeh’s post: found here

The solution is to include the Json and Json Utilities packages in YourGame.Build.cs:

// Fill out your copyright notice in the Description page of Project Settings. 
using UnrealBuildTool;
 
public class TestGame : ModuleRules
{
    public TestGame(TargetInfo Target)
    {
        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore"});
		 
		// Add Json Modules
        PublicDependencyModuleNames.AddRange(new string[] { "Json", "JsonUtilities" });
 
        ...
         
    }
}

You must also REbuild your game for these new packages to be included. It seems like it rebuilds the engine as well though.