C++ Linker LNK2005 when defining a variable

This come form UHT generated code this can be potentially a bug, it generates conficting varable with other varable in your code, can you show header file where you declare this variable? Maybe try removing “_” from name

The quick fix can be removal of UPROPERTY() from that varable it will make UHT complitly ignore the varable, if you not planing to use this variable blueprints you can afford it, or at least until this can be fixed so you can continue working.

Hello! I’m using Unreal Engine 4.16.1 and I’ve been scrathing my head for a while because every time I compile my plugin I’m getting an error message related to my variables, even if I change the name of the variables the Linker is giving me the same error.

Below is the compiler error:

Error LNK2005 “class FString Projectile_Name” (?Projectile_Name@@3VFString@@A) already defined in Module.Smart_Projectile_System.cpp.obj Discordabat C:\Users\elisa\Documents\Discordabat\Discordabat\Intermediate\ProjectFiles\Smart_Projectile_System.generated.cpp.obj 1

Warning LNK4006 “class FString Projectile_Name” (?Projectile_Name@@3VFString@@A) already defined in Module.Smart_Projectile_System.cpp.obj; second definition ignored Discordabat C:\Users\elisa\Documents\Discordabat\Discordabat\Intermediate\ProjectFiles\Smart_Projectile_System.generated.cpp.obj 1

Why I’m getting this error just from defining a simple variable? =( I have cleaned and rebuilted the solution as well.

Thanks! attached is the header file that I’m using! link textI’m afraid that I’m not using the Uproperty macro for those variables but I’m getting the same error, when I try to compile I get:

Error LNK2005 “bool ActivateSubMovement_A” (?ActivateSubMovement_A@@3_NA) already defined in Module.Smart_Projectile_System.cpp.obj

The problem may be in the fact that you are using initialized global variables in your header file. If that header is used in two different modules, and they are linked together, you will get this kind of error.
I guess you should move your definitions to cpp file, and leave only declarations in header file. Something like this:

 FString YOURPROJECTNAME_API Projectile_Name;

And in cpp file:

FString Projectile_Name = FString(TEXT("Projectile Name"));

Anyway if it does not solve your problem it is a bad practice to have this kind of variables in global scope.