External link error with plugin c++ class

Hi,

I have a SERIOUS problem on a module that i’m developing. I made a c++ class that derives from ‘USaveGame’ and everytime I try to compile, it says : unresolved external symbol error : ‘UUCHSave::UUCHSave(void)’ referenced in ‘UCppOptionsSave::UCppOptionsSave(void)’. Can anyone help me on this problem please?

Thanks.

Hi. Have you create a default constructor for your UUCHSave class? Also, did you make it public using macros [YOURMODULENAME]_API? (Replace [YOURMODULENAME] by the actual module name)

I did.

I even added the UCLASS() macro, GENERATED_BODY(), and the generated include.

Could you give more details about UUCHSave and UCppOptionsSave classes please. It seems UCppOptionsSave object contains a subobject UUCHSave or inherited from it, but can not access a constructor of UUCHSave. It also might happen when UUCHSave and UCppOptionsSave belongs different modules and module which contains UCppOptionsSave have no reference to module with UUCHSave inside it’s build.cs script. If it can take place please check if your module’s with UCppOptionsSave build script adds a name of required module to the PrivateDependencyModuleNames array.

So, UCppOptionsSave is from the game module, UUCHSave is from another module, UCppOptionsSave inherits from UUCHsave, i tried to add the other module to my game’s .build.cs, still link errors…

Does your class named UUCHSave marked as exportable? Commonly it looks like
class YOURMODULENAME_API UUCHSave : public UObject

1 Like

It… is.

Hmm… have no idea. Could you show headers and constructors of both classes please?
build.cs of UCppOptionsSave will be helpful too

UCppOptionsSave :

// © 2017 UltraGames. All Rights Reserved.

#pragma once

#include "UCHSave.h"

#include "GameFramework/GameUserSettings.h"

#define QU_HIGHEST 4
#define QU_HIGH    3
#define QU_MEDIUM  2
#define QU_LOW     1
#define QU_LOWEST  0

#include "CppOptionsSave.generated.h"

UCLASS()
class FANTASYPROJECT_API UCppOptionsSave : public UUCHSave
{
	GENERATED_BODY()

public:
	UCppOptionsSave();
	~UCppOptionsSave();

	UFUNCTION(BlueprintCallable)
	void save(bool newDevMode, FString newLanguage = "English", bool newFullscreen = false, int newQuality = 1);

	UFUNCTION(BlueprintCallable, Category = "Load & Save")
	UCppOptionsSave* load();

public:
	UPROPERTY(BlueprintReadWrite, Category = "Options")
	bool devMode;
	UPROPERTY(BlueprintReadWrite, Category = "Options")
	FString language;
	UPROPERTY(BlueprintReadWrite, Category = "Options")
	bool fullscreen;
	UPROPERTY(BlueprintReadWrite, Category = "Options")
	int quality;

private:
	UCppOptionsSave* instance;

	UGameUserSettings* userSetts;
};

UUCHSave :

#pragma once

#include "GameFramework/SaveGame.h"

#include "UCHSave.generated.h"
/**
 *
 */
UCLASS()
class CPPCODERPACK_API UUCHSave : public USaveGame
{
	GENERATED_BODY()

public:
	UUCHSave();

	void save(UUCHSave* instance);
	UUCHSave* load(UUCHSave* instance);

	UPROPERTY(BlueprintReadOnly)
	FString slotName;
};

Build.cs :

// Fill out your copyright notice in the Description page of Project Settings.

using UnrealBuildTool;

public class FantasyProject : ModuleRules
{
	public FantasyProject(TargetInfo Target)
	{
        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });

		PrivateDependencyModuleNames.AddRange(new string[] { "CppCoderPack" });

        PrivateIncludePathModuleNames.AddRange(new string[] { });

        PrivateIncludePaths.AddRange(new string[] { });

        PublicIncludePaths.AddRange(new string[] { });
	}
}

Also, I had to post it as an answer because it was not working as a comment…

Have you tried to make CppCoderPack dependency public?

Nope. Same errors appear

Are they other errors appear before the error you showed? Maybe MSVC project is broken (can be fixed by using context menu of UE project file)

I got no other errors, just warnings about deprecated SetupBinaries(), ModuleRules() and TargetRules()

Also could you check this in your CppCoderPack.uplugin file

218146-enabledbydefault.jpg

It should be “true” and this line should present. If there is no line or it is disabled you have to regenerate MSVC project after fixing that.

Uh, I don’t have that file. It’s not a plugin anymore.

If you use a module this way you have to register in into your .uproject file like here

218148-multiplemodules.jpg

Maybe your main module needs to have a dependency from this custom module in the .uproject file, but not sure

It’s still not working. I already had that in my .uproject file but the loading phase was set to default.

It may sound obvious but do you have UUCHSave::UUCHSave() implementation in your cpp files?

Yes. Same for CppOptionsSave.