1. Home
  2. UE5 Compilation Errors
  3. UE5 C++ Compilation Error...
  4. ❗ LNK2005: Symbol Already Defined – UE5 Linker Error Explained & How to Fix It

❗ LNK2005: Symbol Already Defined – UE5 Linker Error Explained & How to Fix It

Why You’re Seeing This Error

LNK2005 means the linker has found multiple definitions of the same symbol — often a function or variable — and doesn’t know which one to use.

In UE5, this often happens when:

  • You define a variable or function in a header file without making it inline or guarding it
  • You accidentally include the same symbol multiple times
  • You define a static or const variable globally without extern
  • You don’t use #pragma once or include guards in your headers
  • You define a USTRUCT() or UENUM() in multiple translation units

💥 Example Error Message

LNK2005: "int32 MyGlobalValue" already defined in MyActor.cpp.obj

🛠️ Example Code

// MyGlobals.h
int32 MyGlobalValue = 100; // ❌ This creates a definition in every .cpp that includes this header

✅ How to Fix LNK2005 in UE5 – Step-by-Step


✔️ 1. Declare Global Variables with extern in Headers, Define in .cpp

Header (MyGlobals.h):

extern int32 MyGlobalValue; // ✅ Declaration only

Source (MyGlobals.cpp):

int32 MyGlobalValue = 100; // ✅ Single definition

✔️ 2. Use #pragma once or Include Guards in Headers

Every header file should start with:

#pragma once

Or, the old-school way:

#ifndef MY_HEADER_H
#define MY_HEADER_H
// ...
#endif

This prevents duplicate includes that cause linker conflicts.


✔️ 3. Mark Functions inline If Defined in Headers

If you must define a function in a header, mark it inline to avoid multiple definitions.

Fix:

inline int32 GetDefaultValue() { return 42; }

✔️ 4. Avoid Defining USTRUCTs or UENUMs in Multiple Files

UE5 doesn’t allow splitting the same USTRUCT() across multiple files. Keep your types in one place.


✔️ 5. Don’t Define Non-Static Member Variables in Header Files

If you’re putting logic into header files, be careful not to create global duplicate symbols.


✅ Summary: How to Fix LNK2005 in UE5

CauseFix Example
Global variable defined in headerUse extern in header, define in one .cpp
Header included in multiple .cpp filesAdd #pragma once to all headers
Non-inline function defined in headerMark it inline, or move definition to .cpp
Multiple USTRUCT()/UENUM() declarationsKeep them in a single header/source file
Static const improperly scopedDefine static const values inside .cpp if reused

Was this article helpful to you? Yes No

How can we help?