Download

Compiler Error (Linking Error)? Unresolved External Symbol

Hey guys,

can someone please explains a way to fix this compiler error? I’ve tried to look at some sources but I don’t seems to get the answer.
Is the problem lies in missing headers?

What does linking error means?

61f54c9fa9220ded00da505a92d733dfda784e1b.jpeg

I am very new at C++ and programming. Can I please get some help with detailed step?

I tried to follow FPS game mode tutorial from https://wiki.unrealengine.com/First_Person_Shooter_C%2B%2B_Tutorial

I thought it would be a good start. I’m pretty sure I followed every single step as mentioned but in the end I got stuck in the first compiling step.

Here is the code I changed according to the tutorial


#include "Shattered_Code.h"
#include "Shattered_CodeGameMode.h"


AShattered_CodeGameMode::AShattered_CodeGameMode(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

	Super::BeginPlay();
	StartMatch();
	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("HELLO WORLD"));
	}
}


#pragma once

#include "GameFramework/GameMode.h"
#include "FPSGame_Mode.generated.h"

/**
 * 
 */
UCLASS()
class SHATTERED_CODE_API AFPSGame_Mode : public AGameMode
{
	GENERATED_UCLASS_BODY()

	virtual void StartPlay() override; //at Start// 
	
	
};


Also I want to know where Start Play is derived from. Is it necessary to a certain header for StartPlay to work?

Super::BeginPlay() is a method declaration, you have to define it in the .cpp:

AShattered_CodeGameMode::StartPlay()
{
Super::StartPlay();
}

Instead you call it in the Constructor via Super::BeginPlay() , I guess you got a mistake in the name there ? (BeginPlay vs StartPlay?)

Wups, Thanks for that. I place the method in the obvious wrong place. I will try to fix it and see how it goes

Edit:

I added the function below the constructor

but I get this Error

Error 1 error C2509: ‘BeginPlay’ : member function not declared in ‘AShattered_CodeGameMode’ D:\Unreal_Projects\Shattered_Prototype\Shattered_Code\Source\Shattered_Code\Shattered_CodeGameMode.cpp 16 1 Shattered_Code

The code is as follow



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

#include "Shattered_Code.h"
#include "Shattered_CodeGameMode.h"


AShattered_CodeGameMode::AShattered_CodeGameMode(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

	
}


void AShattered_CodeGameMode::BeginPlay()
{
	Super::BeginPlay();

	StartMatch();

	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("HELLO WORLD"));
	}
}

How to declare a function??

You have to declare a function in the .h file (the 2nd code snippet in your first post), like this:


virtual void StartPlay() override; //at Start//

You declared STARTPLAY though, and if you write BeginPlay instead, you can use it in the .cpp file, like you just did:

.cpp



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

#include "Shattered_Code.h"
#include "Shattered_CodeGameMode.h"


AShattered_CodeGameMode::AShattered_CodeGameMode(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

	
}


void AShattered_CodeGameMode::BeginPlay()
{
	Super::BeginPlay();

	StartMatch();

	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("HELLO WORLD"));
	}
}




#pragma once

#include "GameFramework/GameMode.h"
#include "FPSGame_Mode.generated.h"

/**
 * 
 */
UCLASS()
class SHATTERED_CODE_API AFPSGame_Mode : public AGameMode
{
	GENERATED_UCLASS_BODY()

	virtual void BeginPlay() override; //at Start// 
	
	
};


I didn’t test it, but that should work :slight_smile:

Hmm :frowning: It still gives me unresolved external symbol :frowning:

Sry to confuse you but I made a mistake on the placement.

Ignore the Shattered_Code . I need to print a simple text from FPSGame_Mode Class

This is the .cpp file


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

#include "Shattered_Code.h"
#include "FPSGame_Mode.h"
#include "Engine.h"  

AFPSGame_Mode::AFPSGame_Mode(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

}


void AFPSGame_Mode::StartPlay()
{
	Super::StartPlay();

	StartMatch();

	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("HELLO WORLD"));
	}
}

and this is the header


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

#pragma once

#include "GameFramework/GameMode.h"
#include "FPSGame_Mode.generated.h"

/**
 * 
 */
UCLASS()
class SHATTERED_CODE_API AFPSGame_Mode : public AGameMode
{
	GENERATED_UCLASS_BODY()

	virtual void StartPlay() override; //at Start// 
	
	
};


I think this should be fine, and a simple task. however I still get this error :frowning:


Error	1	error LNK2001: unresolved external symbol "public: virtual void __cdecl AShattered_CodeGameMode::StartPlay(void)" (?StartPlay@AShattered_CodeGameMode@@UEAAXXZ)	D:\Unreal_Projects\Shattered_Prototype\Shattered_Code\Intermediate\ProjectFiles\Shattered_CodeGameMode.cpp.obj	Shattered_Code


Wups… I declared another StartPlay() in another header file… It’s working now. Thank you very much! :slight_smile: