Hello, i have a question about modules. I am trying to create a custom module with cpp files and header files. Then I want to link it to my "CNC "primary game module and use the functions in "Test"custom module at begin play event of my “Machine” actor of “CNC” module. When I compile, I get an error message as below;
ld.lld: error: undefined symbol: summation(int, int)
>>> referenced by Machine.cpp:129 (/home/enes/Documents/Unreal Projects/CNC/Source/CNC/Machine.cpp:129)
>>> /home/enes/Documents/Unreal Projects/CNC/Intermediate/Build/Linux/B4D820EA/UnrealEditor/Development/CNC/Machine.cpp.o:(AMachine::BeginPlay())
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
I created below “Test Module” files
Source/Test/Test.Build.cs:
// Copyright Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
public class Test : ModuleRules
{
public Test(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "EnhancedInput"});
}
}
Source/Test/Test.h:
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
Source/Test/Test.cpp:
// Copyright Epic Games, Inc. All Rights Reserved.
#include "Test.h"
#include "Modules/ModuleManager.h"
IMPLEMENT_MODULE(FDefaultModuleImpl, Test);
Source/Test/Foo.h:
int summation(int a, int b);
Source/Test/Foo.cpp:
#include "Foo.h"
int summation(int a, int b)
{
return a + b;
}
I edited the “CNC” primary game module to utilize the function in Foo.h as below
Source/CNC/CNC.Build.cs
// Copyright Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
public class CNC : ModuleRules
{
public CNC(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "EnhancedInput", "Test"});
PublicIncludePaths.AddRange(new string[] {"Test"});
}
}
Finally I included the Foo.h in my actor “Machine.cpp” that belongs to “CNC” primary module and added a summation function.
The compilation fails. Can you help me solving this please?