Plugin Compile error LNK2001 and LNK1120

Hello everyone,

I am attempting to create my own plugin. The version of Unreal Engine I am using is 5.0.3.

As a beginner, I wrote a program to define a float variable and output its value. However, this results in a compilation error.

Below is the current content of the header file and cpp file:

sEasingBPLibrary.h:

// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "Kismet/BlueprintFunctionLibrary.h"
#include "sEasingBPLibrary.generated.h"

UCLASS()
class USEASING_API UsEasingBPLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_UCLASS_BODY()

	UFUNCTION(BlueprintCallable, meta = (DisplayName = "Execute Sample function", Keywords = "sEasing sample test testing"), Category = "sEasingTesting")
	static float sEasingSampleFunction(float Param);

	static float test; // this is my code
};

sEasingBPLibrary.cpp:

// Copyright Epic Games, Inc. All Rights Reserved.

#include "sEasingBPLibrary.h"
#include "sEasing.h"

UsEasingBPLibrary::UsEasingBPLibrary(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
	test = 10;
}

float UsEasingBPLibrary::sEasingSampleFunction(float Param)
{
	return test;
}

The error message is as follows. Although it seems that there is a character encoding issue, it appears to be a linker error. Others may have encountered the same error. Can anyone knowledgeable about this provide assistance?

Module.sEasing.cpp.obj : error LNK2001: ?O???V???{?? "public: static float UsEasingBPLibrary::test" (?test@UsEasingBPLibrary@@2MA) ?͖???ł?
C:\Users\"USER NAME"\Documents\Unreal Projects\plugin_test3\Plugins\sEasing\Binaries\Win64\UnrealEditor-sEasing-8903.dll : fatal error LNK1120: 1 ???̖???̊O???Q??

Is there anyone else struggling with the same error? Experts, please help!

Thank you.

Unrelated to your linker error, but you should be using GENERATED_BODY instead of GENERATED_UCLASS_BODY. The latter is an old macro that’s been replaced with the former and you can use that in all cases instead of using various UCLASS, USTRUCT or UINTERFACE specific versions.

Onto your linker error: It’s because you haven’t actually defined your static variable of UsEasingBPLibrary::test anywhere. You’ve declared it, but not defined it. In your cpp file you need a line like float UsEasingBPLibrary::test = 0; (or whatever you want to initialize it to. In fact, if you want it initialized to 10, you should do that on that line and not in the constructor for the library.

Somewhat related to the linker error: Blueprint function libraries aren’t meant to have variables, static or otherwise. At best they might have constant values, but they shouldn’t have global state that could be changed and is shared across the entire program.