[C++] Multiple "inconsistent dll linkage" errors

Hi,

I was trying to make a UBTTaskNode for a Behavior Tree, but I think I have done something wrong, probably with the includes, and I have not too much experience with this. I got the following errors:

C:\Documents\Unreal Projects\MyProject2 4.8\Source\MyProject2\buscarBomba.h(21): warning C4996: 'UBTTaskNode::ExecuteTask': This version is deprecated. Please use the one taking reference to UBehaviorTreeComponent rather than a pointer. Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.

C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\AIModule\Classes\BehaviorTree/BTTaskNode.h(109) : see declaration of 'UBTTaskNode::ExecuteTask'

c:\\documents\unreal projects\myproject2 4.8\source\myproject2\buscarBomba.h(21): warning C4996: 'UBTTaskNode::ExecuteTask': This version is deprecated. Please use the one taking reference to UBehaviorTreeComponent rather than a pointer. Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.

C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\AIModule\Classes\BehaviorTree/BTTaskNode.h(109) : see declaration of 'UBTTaskNode::ExecuteTask'

C:\Documents\Unreal Projects\MyProject2 4.8\Source\MyProject2\buscarBomba.cpp(31): warning C4996: FPostConstructInitializeProperties is deprecated and was renamed to FObjectInitializer. Please use that type instead.

C:\Documents\Unreal Projects\MyProject2 4.8\Source\MyProject2\buscarBomba.cpp(32): error C4273: 'UBTTaskNode::UBTTaskNode' : inconsistent dll linkage

C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\AIModule\Classes\BehaviorTree/BTTaskNode.h(29) : see previous definition of '{ctor}'

C:\Documents\Unreal Projects\MyProject2 4.8\Source\MyProject2\buscarBomba.cpp(38): error C4273: 'UBTTaskNode::ExecuteTask' : inconsistent dll linkage

C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\AIModule\Classes\BehaviorTree/BTTaskNode.h(109) : see previous definition of 'ExecuteTask'

C:\Documents\Unreal Projects\MyProject2 4.8\Source\MyProject2\buscarBomba.cpp(107): error C4273: 'UBTNode::GetStaticDescription' : inconsistent dll linkage

C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\AIModule\Classes\BehaviorTree/BTNode.h(130) : see previous definition of 'GetStaticDescription'

My class.h file:

#pragma once
#include "BehaviorTree/BTTaskNode.h"
#include "buscarBomba.generated.h"

/**
 * 
 */
UCLASS()
class MYPROJECT2_API UbuscarBomba : public UBTTaskNode
{
	GENERATED_BODY()
		
	
	virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent * OwnerComp, uint8* NodeMemory) override;
	virtual FString GetStaticDescription() const override;
	virtual float calculateFitness(FVector actorLocation);
};

and cpp:

#include "MyProject2.h"
#include "buscarBomba.h"
#include "AI_Character.h"
#include "globalBestData.h"
#include "MyProject2Character.h"
#include "Engine.h"
#include "Runtime/Core/Public/Math/UnrealMathUtility.h"
#include "Kismet/KismetMathLibrary.h"
#include "BehaviorTree/BTTaskNode.h"

float calculateFitness(FVector x){
	AActor* objetivo;
	for (TObjectIterator<AActor> Itr; Itr; ++Itr)
	{
		if (Itr->GetName() == "Target")
		{
			objetivo = *Itr;
			break;
		}
	}
	FVector posicionObjetivo = objetivo->GetActorLocation();
	FVector aux = x - posicionObjetivo;
	float length = aux.Size();
	float fitness;
	UNavigationSystem* NavSys = UNavigationSystem::GetCurrent(objetivo->());
	NavSys->GetPathLength(x, posicionObjetivo, fitness);
	return fitness;
}

UBTTaskNode::UBTTaskNode(const FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	NodeName = "buscarBomba";
}

EBTNodeResult::Type UBTTaskNode::ExecuteTask(UBehaviorTreeComponent* OwnerComp, uint8* NodeMemory)
{
	AAI_Character* npc = Cast<AAI_Character>(OwnerComp->GetOwner());
	bool buscaBomba = npc->isLeader;
	bool objetivoAlcanzado = npc->goalReached;
	bool haDetectadoEnemigo = npc->disparando;
	FVector posicionActual = npc->GetActorLocation();
	float diferenciaDeInercia = npc->inertiaDifference;
	FVector velocidad = npc->particleVelocity;
	float radioDeAceptacion = 425.0f;
	float r1, r2;
	float w = 0.7f;
	float c1=1.4f, c2=1.4f;
	

	if (buscaBomba && !objetivoAlcanzado && !haDetectadoEnemigo){

		float fitness = calculateFitness(posicionActual);

		if (fitness < npc->bestLocalFitness){
			npc->bestLocalFitness = fitness;
			npc->bestLocalPosition = posicionActual;
		}

		
		UglobalBestData* LoadGameInstance = Cast<UglobalBestData>(UGameplayStatics::CreateSaveGameObject(UglobalBestData::StaticClass()));
		LoadGameInstance = Cast<UglobalBestData>(UGameplayStatics::LoadGameFromSlot(LoadGameInstance->SaveSlotName, LoadGameInstance->UserIndex));
		float bestGlobalFitness = LoadGameInstance->bestGlobalFitness;
		FVector bestGlobalPosition = LoadGameInstance->bestGlobalPosition;

		
		if (fitness < bestGlobalFitness){
			bestGlobalFitness = fitness;
			bestGlobalPosition = posicionActual;
			UglobalBestData* SaveGameInstance = Cast<UglobalBestData>(UGameplayStatics::CreateSaveGameObject(UglobalBestData::StaticClass()));
			SaveGameInstance->bestGlobalFitness = bestGlobalFitness;
			SaveGameInstance->bestGlobalPosition = bestGlobalPosition;
			UGameplayStatics::SaveGameToSlot(SaveGameInstance, SaveGameInstance->SaveSlotName, SaveGameInstance->UserIndex);
		}

		
		if (fitness <= radioDeAceptacion){
						
			npc->goalReached = true;// Actualiza la variable ObjetivoAlcanzado
			return EBTNodeResult::Succeeded;
		}
		
		else{

			r1 = FMath::FRandRange(0.0f, 1.0f);
			r2 = FMath::FRandRange(0.0f, 1.0f);
			npc->inertiaDifference = fmodf(diferenciaDeInercia + 0.025f,w-0.025f);
			npc->particleVelocity = velocidad*(w - npc->inertiaDifference)+(npc->bestLocalPosition - posicionActual)*r1*c1+r2*c2*(bestGlobalPosition - posicionActual);

			posicionActual = posicionActual + npc->particleVelocity;
			FRotator nuevaRotacionNPC = UKismetMathLibrary::FindLookAtRotation(npc->GetActorLocation(), posicionActual);
			FRotator rotacionNPC = npc->GetActorRotation();
			npc->SetActorRotation(FMath::RInterpTo(rotacionNPC, nuevaRotacionNPC, ()->GetDeltaSeconds(), 6.0f));
			npc->GetCharacterMovement()->MaxWalkSpeed = 400;
			npc->SetActorLocation(posicionActual);

			return EBTNodeResult::Succeeded;
		}
	}
	else{
		return EBTNodeResult::Succeeded;
	}
	
}

FString UBTNode::GetStaticDescription() const
{
	return TEXT("Description");
}

Thank you in advance

You added AIModule to build script right?

I have edited my post: I changed the API on the .h file to “MYPROJECT_API” and now I got less errors, but still the “Inconsistent DLL linkage” ones.

I have AIModule in the build script and it doesn’t change anything.

Thank you for your response

1 Like

Hey guilledi-

Could you post the full source and header for your buscaBomba class? The errors you posted are reporting lines of code further into the file than what is in the original post. Additionally one of the errors mentions the use of FPostConstructInitializeProperties. Using FObjectInitializer instead may help.

Cheers

Hi , I posted the full source, the header is the same.

Regarding the FPostConstructInitializeProperties error I couldn’t change it yet (I have moved to a new yesterday, and still have not visual installed), I’ll try it as soon as possible.

Thank you!

Hey guilledi-

There are a few things that may help get your code to compile successfully.

  1. In Line11 there is no class Identifier for the CalculateFitness() class. It should have UbuscarBomba:: preceding it.
  2. In Line30 if you are declaring the header for your class then you need to use UbuscarBomba::UbuscarBomba() instead of UBTTaskNode::UBTTaskNode().
  3. In Line36 if you are overriding the ExecuteTask() from the parent class then you would use UbuscarBomba in place of UBTTaskNode to indicate which function is being overridden.
  4. The same case applies to Line106 in that you need to use UbuscarBomba instead of UBTNode to indicate the function is being overridden in the child.

Due to references to other classes if you are still having compile issues after making these changes then you will need to post the exact errors as well as possibly supply the project to test directly.

Cheers

Thank you very much !

I had to change GENERATED_BODY() to GENERATED_UCLASS_BODY() in the header file because I got an error C2084 (function UbuscarBombaAMyTestActor(const FObjectInitializer &)’ already has a body) but now it compiles perfectly.

In case someone runs into the issue as well. One potential error that can cause those errors is incorrect DLL_EXPORT macro that proceeds class name

3 Likes