Error LNK2001 / LNK2019 / LNK1120

Hey guys, I’m getting these errors and I cannot figure out for the life of me why.

1>LINK : error LNK2001: unresolved external symbol IMPLEMENT_MODULE_ExperienceAPI

1>xAPIAgentComponent.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl FJsonObject::SetStringField(class FString const &,class FString const &)" (__imp_?SetStringField@FJsonObject@@QEAAXAEBVFString@@0@Z) referenced in function "public: class TSharedPtr<class FJsonObject,0> const __cdecl UxAPIAgentComponent::toAgent(void)const " (?toAgent@UxAPIAgentComponent@@QEBA?BV?$TSharedPtr@VFJsonObject@@$0A@@@XZ)

1>xAPIAgentComponent.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl FJsonObject::SetObjectField(class FString const &,class TSharedPtr<class FJsonObject,0> const &)" (__imp_?SetObjectField@FJsonObject@@QEAAXAEBVFString@@AEBV?$TSharedPtr@VFJsonObject@@$0A@@@@Z) referenced in function "public: class TSharedPtr<class FJsonObject,0> const __cdecl UxAPIAgentComponent::toAgent(void)const " (?toAgent@UxAPIAgentComponent@@QEBA?BV?$TSharedPtr@VFJsonObject@@$0A@@@XZ)

1>xAPIAgentComponent.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl FJsonObject::FJsonObject(void)" (__imp_??0FJsonObject@@QEAA@XZ) referenced in function "public: class TSharedPtr<class FJsonObject,0> const __cdecl UxAPIAgentComponent::toAgent(void)const " (?toAgent@UxAPIAgentComponent@@QEBA?BV?$TSharedPtr@VFJsonObject@@$0A@@@XZ)

1>xAPIAgentComponent.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl FJsonObject::~FJsonObject(void)" (__imp_??1FJsonObject@@QEAA@XZ) referenced in function "public: virtual void __cdecl SharedPointerInternals::TReferenceControllerWithDeleter<class FJsonObject,struct SharedPointerInternals::DefaultDeleter<class FJsonObject> >::DestroyObject(void)" (?DestroyObject@?$TReferenceControllerWithDeleter@VFJsonObject@@U?$DefaultDeleter@VFJsonObject@@@SharedPointerInternals@@@SharedPointerInternals@@UEAAXXZ)

1>F:\UnrealEngine-release\Engine\Plugins\ExperienceAPI\Binaries\Win64\UE4Editor-ExperienceAPI.dll : fatal error LNK1120: 5 unresolved externals

This is my ExperienceAPI.Build.cs

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.

namespace UnrealBuildTool.Rules
{
	public class ExperienceAPI : ModuleRules
	{
		public ExperienceAPI(ReadOnlyTargetRules Target) : base(Target)
		{
			PublicIncludePaths.AddRange(
				new string[] {
					// ... add public include paths required here ...
				}
				);

			PrivateIncludePaths.AddRange(
				new string[] {
					// ... add other private include paths required here ...
				}
				);

			PublicDependencyModuleNames.AddRange(
				new string[]
				{
					"Core",
                    "CoreUObject",
					"Engine",
					// ... add other public dependencies that you statically link with here ...
				}
				);

			PrivateDependencyModuleNames.AddRange(
				new string[]
				{
					// ... add private dependencies that you statically link with here ...
				}
				);

			DynamicallyLoadedModuleNames.AddRange(
				new string[]
				{
					// ... add any modules that your module loads dynamically here ...
				}
				);
		}
	}
}

Heres the xAPIAgentComponent.h

#pragma once


#include "Components/ActorComponent.h"
#include "Json.h"
#include "xAPIAgentComponent.generated.h"

DECLARE_LOG_CATEGORY_EXTERN(LogXapi, Log, All);

UENUM(BlueprintType)
enum class EAgentIFIType : uint8
{
		MBOX			UMETA(DisplayName = "mbox"),
		MBOX_SHA1SUM	UMETA(DisplayName = "mbox_sha1sum"),
		OPENID			UMETA(DisplayName = "openid"),
		ACCOUNT			UMETA(DisplayName = "account")
};

USTRUCT(BlueprintType)
struct FAgentAccountInfo
{
	GENERATED_USTRUCT_BODY()
public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = ExperienceAPI)
		FString Homepage;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = ExperienceAPI)
		FString Name;
};

/*
 * A component representing an xAPI Agent, i.e. a learner
 */

UCLASS(BlueprintType, meta = (BlueprintSpawnableComponent))
class EXPERIENCEAPI_API UxAPIAgentComponent : public UActorComponent
{
	GENERATED_BODY()

public:

	UPROPERTY(EditAnywhere, Category = ExperienceAPI)
		FString Name;

	UPROPERTY(EditAnywhere, Category = ExperienceAPI)
		EAgentIFIType ifi_type;
		//TEnumAsByte<EAgentIFIType::Type> ifi_type;

	UPROPERTY(EditAnywhere, Category = ExperienceAPI)
		FString Mbox;

	UPROPERTY(EditAnywhere, Category = ExperienceAPI)
		FString MboxSha1Sum;

	UPROPERTY(EditAnywhere, Category = ExperienceAPI)
		FString OpenID;

	UPROPERTY(EditAnywhere, Category = ExperienceAPI)
		FAgentAccountInfo Account;

	UxAPIAgentComponent();

	const TSharedPtr<FJsonObject> toAgent() const;
};

xAPIAgentComponent.cpp

#include "xAPIAgentComponent.h"

DEFINE_LOG_CATEGORY(LogXapi);

UxAPIAgentComponent::UxAPIAgentComponent()
{

}


const TSharedPtr<FJsonObject> UxAPIAgentComponent::toAgent() const
{
	// initialize the object we'll be returning
	TSharedPtr<FJsonObject> agent(new FJsonObject());

	// specify that the return object is an Agent
	agent->SetStringField(TEXT("objectType"), TEXT("Agent"));

	// add the general-purpose name if specified
	if (!Name.IsEmpty()){
		agent->SetStringField(TEXT("name"), Name);
	}

	// add the IFI specified by ifi_type
	switch (ifi_type){
	case EAgentIFIType::MBOX:

		agent->SetStringField(TEXT("mbox"), Mbox);
		break;

	case EAgentIFIType::MBOX_SHA1SUM:

		agent->SetStringField(TEXT("mbox_sha1sum"), MboxSha1Sum);
		break;

	case EAgentIFIType::OPENID:

		agent->SetStringField(TEXT("openid"), OpenID);
		break;

	case EAgentIFIType::ACCOUNT:

		TSharedPtr<FJsonObject> accountObj(new FJsonObject());
		accountObj->SetStringField(TEXT("homePage"), Account.Homepage);
		accountObj->SetStringField(TEXT("name"), Account.Name);

		agent->SetObjectField(TEXT("account"), accountObj);
		break;
	}

	return agent;
}

Any help would be greatly appriciated!!!

You need to add Json to your dependencies, probably also want to add JsonUtilitie.
Don’t forget to regenerate your visual studio project files after adding it

 PublicDependencyModuleNames.AddRange(
			new string[] {
                     "Core",
                     "CoreUObject",
                     "Engine",
                     // ... add other public dependencies that you statically link with here ...

                    "Json",
                    "JsonUtilities"
            }
		);

Ill give that a go, I did have it in there previously but did not rebuild the VS project files afterwards… Will see what happens!

I just get this error now

    1>LINK : error LNK2001: unresolved external symbol IMPLEMENT_MODULE_ExperienceAPI
    1>F:\UnrealEngine-release\Engine\Plugins\ExperienceAPI\Binaries\Win64\UE4Editor-ExperienceAPI.dll : fatal error LNK1120: 1 unresolved externals

As well as this

    1>  [2/6] xAPIAgentComponent.cpp
    1>F:\UnrealEngine-release\Engine\Source\Runtime\Json\Public\Json.h(10): warning : Monolithic headers should not be used by this module. Please change it to explicitly include the headers it needs.
    1>  [3/6] xAPIAgentComponent.gen.cpp
    1>F:\UnrealEngine-release\Engine\Source\Runtime\Json\Public\Json.h(10): warning : Monolithic headers should not be used by this module. Please change it to explicitly include the headers it needs.

If I take out the Json.h includes I dont get the monolithic error.

don’t have the project where we use the Json module at hand, will have a look tomorrow

Thanks bud, will wait and thanks for taking the time!

k
looked into our project we include
#include “JsonObject.h”

The error message is about only including the headers you need not everything.
A good resource for finding the right headers to include is normally the unreal api documentation on the web.
Google class in question
“ue4 api FJsonObject”
which in this case leads you here

and on the bottom under references, you see what you need to include
Module + Header

For the header you need to figure out what part of the path you can leave out
Runtime/Json/Public/Dom/JsonObject.h
in this case apparently everything but the JsonObject.h
quite often it’s everything including “Public” or everything including Runtime/Engine/Classes/

I’ve managed to fix that issue now thanks to you, the latest one that keeps popping up is to the IMPLEMENT_MODULE_ExperienceAPI. Turns out I needed to copy the module name from the - class EXPERIENCEAPI_API Ux… - to the uproject file as all caps and it compiles with no errors… Thanks for the help man