Error LNK2019: unresolved external symbol; Fatal error LNK1120; c++ modules

I’m trying to make a simple thing. I have an InteractableActor.cpp with a large sphere collision around it. When my Character (DerrickCharacter.cpp) enters that sphere, I want to print a debug message.

This is the simple code I wrote on the Sphere OnBeginOverlapp function in InteractableActor.cpp.
Keep in mind, the function works properly when I just put the debug message, it’s when I add the casting part that it won’t compile.

void AInteractableActor::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	ADerrickCharacter* DerrickCharacter = Cast<ADerrickCharacter>(OtherActor);

	if (DerrickCharacter)
	{ 

		GEngine->AddOnScreenDebugMessage(0, 5.0f, FColor::Yellow, TEXT("Begin Overlap"));
	} 
}

But since it’s not a compiler error and instead a linker error, I guess the problem is in communication between my .cpp and .h files.

Important: my character class - DerrickCharacter.cpp is inside a defualt project module called “Derrick” (Name of the unreal project).
My InteractableActor.cpp is however in another c++ module I created called “Interactable”, so I guess the problem is that I didn’t properly link these modules or something?

In my InteractableActor.cpp I did include “#include <Derrick/DerrickCharacter.h>”
and my Interactable.Build.css looks like this:

using UnrealBuildTool;

public class Interactable : ModuleRules
{
    public Interactable(ReadOnlyTargetRules Target) : base(Target)
    {
        PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "UMG", "Derrick"});
    }
}

So I did include main project “Derrick” module as a dependency inside my custom “Interactable” module, and I did “#include <Derrick/DerrickCharacter.h>” in my InteractableActor.cpp but I still get this linker error when compiling.

Does anyone know what could be the problem?

Did you export your class with DERRICK_API? e.g.
class DERRICK_API ADerrickCharacter

2 Likes

Omg, I’m so stupid. Yeah, that’s it. Thanks a lot man!