Quick answer: LNK2019 means your code compiled against a declaration, and the linker then found no compiled definition for it. In Unreal the usual cause is a module missing from PublicDependencyModuleNames or PrivateDependencyModuleNames in your .Build.cs: the symbol says __declspec(dllimport) and names an engine class. Otherwise a function was declared and never defined, such as a missing _Implementation or GetLifetimeReplicatedProps, or a class in another module lacks its MODULENAME_API export macro.
The compiler was satisfied, which is what makes this error confusing: every header was found and every call type-checked. The failure is one step later, when the linker goes looking for the machine code behind a name and comes back with nothing. The error text is long and looks hostile, but it contains the answer. It names the symbol, says whether it was expected to come from another DLL, and says which of your functions asked for it. This guide shows how to read those three parts and then works through the causes Unreal projects actually hit, with the Build.cs lines and code changes that fix each.
- The exact error
- How to read the symbol
- Fix 1: add the module to Build.cs
- Fix 2: export classes that other modules use
- Fix 3: define what you declared
- Fix 4: make sure the .cpp is compiled
- Fix 5: clear stale generated code
- Fix 6: keep editor-only code out of runtime modules
- When it linked yesterday: unity builds
- How to confirm the fix
- Where Bugnet meets this error
- Related guides
- Frequently asked questions
The exact error
MyHUD.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class UClass * __cdecl UUserWidget::GetPrivateStaticClass(void)" (__imp_?GetPrivateStaticClass@UUserWidget@@CAPEAVUClass@@XZ) referenced in function "public: void __cdecl AMyHUD::ShowMenu(void)" (?ShowMenu@AMyHUD@@QEAAXXZ)
D:\Projects\MyGame\Binaries\Win64\UnrealEditor-MyGame.dll : fatal error LNK1120: 1 unresolved externals
Its sibling, LNK2001, is the same failure for a symbol that is not referenced from inside a function body, which in practice means virtual functions and static data members:
MyCharacter.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl AMyCharacter::GetLifetimeReplicatedProps(class TArray<class FLifetimeProperty,class TSizedDefaultAllocator<32> > &)const " (...)
LNK1120 is only the count of unresolved symbols and needs no fix of its own. With unity builds on, the object file is often named Module.MyGame.cpp.obj or similar. On Mac and Linux the same failure reads Undefined symbols for architecture arm64: or ld.lld: error: undefined symbol:, and everything below applies.
How to read the symbol
Read it in the Output window of Visual Studio or Rider. The Error List shows the same text mixed with IntelliSense noise and is harder to copy from. Three parts matter:
- The symbol in quotes is the function or variable with no definition, with its full signature.
__declspec(dllimport)(and the__imp_prefix on the decorated name) means the compiler was told this symbol lives in another module’s DLL. Its absence means the linker expected to find the definition inside the module being linked.- “referenced in function” is where in your code the call is.
| What the symbol looks like | Most likely cause |
|---|---|
dllimport, an engine or plugin class (UUserWidget, FHttpModule) | Module missing from Build.cs |
dllimport, a class from your own second module or plugin | Missing or wrong _API macro, or the module is not a dependency |
No dllimport, your own class | Declared but never defined, a signature mismatch, or the .cpp is not being compiled |
Ends in _Implementation or _Validate | BlueprintNativeEvent or RPC without its body |
GetLifetimeReplicatedProps | A Replicated property with no registration function |
Z_Construct_UClass_… or GetPrivateStaticClass for your own class | Class not exported to the module using it, or stale generated code |
| Links in the editor, fails when packaging | Editor-only code used from a runtime module |
Fix 1: add the module to Build.cs
Including a header only makes the declarations visible. To link against the code, the module that owns it must be listed in Source/MyGame/MyGame.Build.cs:
PublicDependencyModuleNames.AddRange(new string[] {
"Core", "CoreUObject", "Engine", "InputCore", "UMG"
});
PrivateDependencyModuleNames.AddRange(new string[] {
"Slate", "SlateCore"
});
Use the public list when your own public headers include that module’s headers, and the private list when only your .cpp files do. To find which module owns a class, open its page in Epic’s API reference, which lists the module and the include path, or look at where the header lives: for Engine/Source/Runtime/UMG/Public/Blueprint/UserWidget.h the module is the folder above Public, so UMG. For plugin code the pattern is Engine/Plugins/…/Source/<Module>/Public.
| Symbol mentions | Add module |
|---|---|
UUserWidget, UWidget, UButton, UWidgetBlueprintLibrary | UMG |
SWidget, SCompoundWidget, FSlateBrush | SlateCore |
SButton, FSlateApplication | Slate |
AAIController, UBehaviorTree, UBlackboardComponent, UBTTaskNode | AIModule |
UGameplayTask, IGameplayTaskOwnerInterface | GameplayTasks |
UNavigationSystemV1 | NavigationSystem |
FGameplayTag, FGameplayTagContainer | GameplayTags |
UAbilitySystemComponent, UGameplayAbility, UAttributeSet | GameplayAbilities |
UNiagaraComponent, UNiagaraFunctionLibrary | Niagara |
UEnhancedInputComponent, UInputAction | EnhancedInput |
IOnlineSubsystem | OnlineSubsystem |
FHttpModule, IHttpRequest | HTTP |
FJsonObject, FJsonSerializer | Json |
FJsonObjectConverter | JsonUtilities |
UPhysicalMaterial | PhysicsCore |
UDeveloperSettings | DeveloperSettings |
One trap in that table: a Behavior Tree task or any class deriving from UBTTaskNode needs GameplayTasks as well as AIModule, because the base class implements a GameplayTasks interface. A module that lives in a plugin (GameplayAbilities is the usual one) also needs the plugin enabled in the .uproject. Without that the build can link and the editor then fails to load your game module, which is the situation in “The game module could not be loaded”.
Fix 2: export classes that other modules use
On Windows a class is only visible outside its DLL if it is marked for export. Unreal generates one macro per module for that, the module name in capitals followed by _API:
// Source/Inventory/Public/InventoryComponent.h
UCLASS()
class INVENTORY_API UInventoryComponent : public UActorComponent
{
GENERATED_BODY()
public:
void AddItem(FName ItemId);
};
Leave the macro off and any other module calling AddItem gets LNK2019. Use the wrong one, typically MYGAME_API left behind after moving a file into a plugin, and the class is declared as imported inside its own module. The build then fails either at compile time with C2491, “definition of dllimport function not allowed”, or at link time with unresolved dllimport symbols for that class. Free functions and classes that are not UCLASSes need the macro too. UCLASS(MinimalAPI) exports only the type information, so individual functions still need the macro. Some engine classes are MinimalAPI with unexported functions; if the unresolved symbol is one of those, adding modules will not help, and you need a different, exported function.
Fix 3: define what you declared
When the symbol is your own class and there is no dllimport, the definition is missing or does not match. The header:
UFUNCTION(BlueprintNativeEvent)
void OnPickedUp(AActor* By);
UFUNCTION(Server, Reliable, WithValidation)
void ServerFire(FVector Origin);
UPROPERTY(Replicated)
int32 Ammo;
static int32 LiveCount;
What each line requires in the .cpp:
// BlueprintNativeEvent: you write _Implementation, the generated code writes OnPickedUp
void AMyWeapon::OnPickedUp_Implementation(AActor* By) { }
// RPC: _Implementation, plus _Validate because of WithValidation
void AMyWeapon::ServerFire_Implementation(FVector Origin) { }
bool AMyWeapon::ServerFire_Validate(FVector Origin) { return true; }
// Replicated property: the generated code declares this, you must define it
void AMyWeapon::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(AMyWeapon, Ammo); // needs #include "Net/UnrealNetwork.h"
}
// Static data member: one definition in one .cpp
int32 AMyWeapon::LiveCount = 0;
Other members of this family: a constructor declared in the header with no body, a virtual function declared and never defined (LNK2001, because the virtual table refers to it), and DECLARE_LOG_CATEGORY_EXTERN(LogMyGame, Log, All); in a header without DEFINE_LOG_CATEGORY(LogMyGame); in a .cpp.
A definition that does not match counts as missing. Compare the quoted symbol with your .cpp character by character: a dropped const, FString against const FString&, or a body written as void Fire() without the AMyWeapon:: scope, which defines an unrelated free function and leaves the member undefined.
Fix 4: make sure the .cpp is compiled
UnrealBuildTool compiles the source files it finds under the module’s folder. It does not read the Visual Studio project, so a file that only exists in the solution is not built. The usual ways to end up there:
- Visual Studio’s Add New Item saved the file under
Intermediate/ProjectFiles, its default location for an Unreal solution. Move the file underSource/MyGame/, or create classes from the editor (Tools > New C++ Class). - The file sits in a folder named after a platform. Folders called
Mac,Linux,AndroidorIOSare only compiled for that platform, so aSource/MyGame/Linux/folder vanishes from a Windows build. - The file is in another module’s folder, so it was compiled into a different DLL.
After moving files, right-click the .uproject and choose Generate Visual Studio project files so the solution matches what is on disk.
Template and inline code is a variation of the same problem. A template member function, or a function marked inline or FORCEINLINE, whose body is in a .cpp can only be used from that .cpp. Move the body into the header.
Fix 5: clear stale generated code
If the unresolved symbols are things you never wrote (Z_Construct_UClass_AMyActor, StaticClass, GetPrivateStaticClass) for a class in the same module, the output of UnrealHeaderTool is out of step with the source. It tends to follow adding UCLASS or GENERATED_BODY to an existing class, renaming a class, or switching branches. Close the editor, delete the project’s Binaries and Intermediate folders (and the same two inside each project plugin), regenerate project files and rebuild. Leave Saved and Content alone. When the same symbols are unresolved from a different module, go back to Fix 2: the class is not exported. For the broader rebuild procedure see “Project could not be compiled”.
Fix 6: keep editor-only code out of runtime modules
A build that links for the editor and fails with LNK2019 when you package is using something that only exists in editor builds. Either a function whose body sits inside #if WITH_EDITOR is called from code outside that guard, or a runtime module leans on an editor module. Guard the call sites and make the dependency conditional:
// MyGame.Build.cs
if (Target.bBuildEditor)
{
PrivateDependencyModuleNames.Add("UnrealEd");
}
#if WITH_EDITOR
RebuildPreviewMesh(); // defined inside #if WITH_EDITOR in the .cpp
#endif
Anything more than a few guarded lines belongs in a separate module with "Type": "Editor" in the .uproject or .uplugin, which is never built into the game. A runtime module declared with the wrong type causes the mirror problem, a module that exists in the editor and is absent from the packaged game; see “Plugin failed to load because module could not be found” for the load-time side of that.
When it linked yesterday: unity builds
By default UnrealBuildTool merges many .cpp files into a few large ones. Inside a merged file, a helper function or template defined in one .cpp is visible to the others, so code with a missing include or a body in the wrong file builds anyway. Then the grouping changes, because you added a file or because the adaptive mode pulled a file you are editing out of the merged set, and the error appears in code nobody touched. Reproduce it on purpose by adding bUseUnityBuild = false; to your Target.cs files for one build, and fix what falls out.
How to confirm the fix
Build the editor target (Development Editor) and then a game target, either Development or a full package for one platform, since editor-only mistakes only show in the second. If another module or plugin uses the class, build that too. A non-unity build once before release catches the ordering-dependent cases. The fix is complete when all three finish without LNK2019, LNK2001 or LNK1120 in the Output window.
Where Bugnet meets this error
A link error happens on your machine before a game exists, so there is nothing for a bug reporter to capture, and Bugnet has no part in fixing it. It is, though, a place you can meet this exact error: the Bugnet Unreal SDK is two source files you add to your game module, and it uses HTTP, Json, JsonUtilities, ImageWrapper and OnlineSubsystem. Leave one out of Build.cs and you get LNK2019 naming FHttpModule or FJsonObject, which is Fix 1. The install script checks your Build.cs and lists the modules it lacks. Once the game links and ships, the SDK’s job starts: fatal errors and failed asserts are filed with the engine’s message and recent log lines. See the SDK docs.
Related guides
- How to Fix “The game module could not be loaded” in Unreal Engine
- How to Fix “Project could not be compiled. Try rebuilding from source manually” in Unreal
- How to Fix “Plugin ‘X’ failed to load because module ‘X’ could not be found” in Unreal
- How to Fix “The following modules are missing or built with a different engine version” in Unreal
- check vs ensure vs verify in Unreal Engine: Which Assert to Use and What Ships
Frequently asked questions
What does LNK2019 unresolved external symbol mean in Unreal Engine?
The compiler saw a declaration for a function or variable, and the linker then could not find its compiled definition. In Unreal that is usually a module missing from Build.cs, a function declared in a header and never defined, or a class in another module without its API export macro.
How do I know which module to add to Build.cs?
Take the class name from the error and look it up in the Unreal API reference, which lists its module, or find its header in the engine source. The module is the folder that contains the Public or Classes folder holding that header, for example UMG for UserWidget.h.
What is the difference between LNK2019 and LNK2001?
Both mean a symbol has no definition. LNK2019 names the function that referenced it. LNK2001 appears when the reference is not inside a function, which mostly means virtual functions referenced by the virtual table and static data members. The fixes are the same.
Why does my project build in the editor but fail with LNK2019 when packaging?
The code uses something that only exists in editor builds: a function defined inside a WITH_EDITOR block, or an editor module such as UnrealEd. Wrap the calls in WITH_EDITOR, add editor modules only when Target.bBuildEditor is true, or move the code to an Editor module.
Does deleting Binaries and Intermediate fix LNK2019?
Only when the unresolved symbols are generated ones for a class in the same module, which points to stale UnrealHeaderTool output. For a missing module, a missing function body or a missing export macro, a clean rebuild reproduces the same error.
Look for dllimport in the symbol first. With it, the answer is in Build.cs or an API macro; without it, the answer is a missing or mismatched definition in your own .cpp.