Hi,
I am following this tutorial ( link ) which shows how to link a static library. To be sure it is not my library that is causing an issue I have created the example library in the MSDN tutorial. The library simply has a functions which sums two inputs and returns a double. I have tested the library in a c++ project (no UE4) and it works fine.
When I follow the steps and make the changes (shown below) to the build.cs file I get errors. The changes to the build.cs file are simply copy paste from the tutorial with necessary function names changed. My code can have the #include without errors but whenever I try to call a function it does not work. I would really appreciate any help.
If anyone has linked a static library in 4.16 is there any chance you could paste your build.cs to see how you have done it. I think the tutorial is only for pre 4.15.
using System.IO;
using UnrealBuildTool;
public class TheTable : ModuleRules
{
public TheTable(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
PrivateDependencyModuleNames.AddRange(new string[] { });
// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
}
private string ModulePath
{
get { return ModuleDirectory; }
}
private string ThirdPartyPath
{
get { return Path.GetFullPath(Path.Combine(ModulePath, "../ThirdParty/")); }
}
public TheTable(TargetInfo Target)
{
LoadBobsMagic(Target);
}
public bool LoadBobsMagic(TargetInfo Target)
{
bool isLibrarySupported = false;
if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))
{
isLibrarySupported = true;
string PlatformString = (Target.Platform == UnrealTargetPlatform.Win64) ? "x64" : "x86";
string LibrariesPath = Path.Combine(ThirdPartyPath, "MathFuncsLib", "Libraries");
/*
test your path with:
using System; // Console.WriteLine("");
Console.WriteLine("... LibrariesPath -> " + LibrariesPath);
*/
PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "MathFuncsLib." + PlatformString + ".lib"));
}
if (isLibrarySupported)
{
// Include path
PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "MathFuncsLib", "Includes"));
}
Definitions.Add(string.Format("WITH_BOBS_MAGIC_BINDING={0}", isLibrarySupported ? 1 : 0));
return isLibrarySupported;
}
}
Here is the code I am am calling (within a component of a pawn):
double UGetDataForRL::testlibs(double a, double b)
{
double test = MathFuncs::MyMathFuncs::Add(a, b);
return test;
}
The errors i get are:
Warning CS0618 ‘UnrealBuildTool.ModuleRules.ModuleRules()’ is obsolete: ‘Please change your module constructor to take a ReadOnlyTargetRules parameter, and pass it to the base class constructor (eg. “MyModuleRules(ReadOnlyTargetRules Target) : base(Target)”).’ TheTable c:\Users\Documents\Unreal Projects\03_BuildingEscape\TheTable\Source\TheTable\TheTable.Build.cs 36
Warning Module constructors should take a ReadOnlyTargetRules argument (rather than a TargetInfo argument) and pass it to the base class constructor from 4.15 onwards. Please update the method signature. TheTable C:\Users\Documents\Unreal Projects\03_BuildingEscape\TheTable\Source\TheTable\TheTable.Build.cs 1
Error LNK2019 unresolved external symbol “public: static double __cdecl MathFuncs::MyMathFuncs::Add(double,double)” (?Add@MyMathFuncs@MathFuncs@@SANNN@Z) referenced in function “public: double __cdecl UGetDataForRL::testlibs(double,double)” (?testlibs@UGetDataForRL@@QEAANNN@Z) TheTable C:\Users\Documents\Unreal Projects\03_BuildingEscape\TheTable\Intermediate\ProjectFiles\GetDataForRL.cpp.obj 1
Error LNK1120 1 unresolved externals TheTable C:\Users\Documents\Unreal Projects\03_BuildingEscape\TheTable\Binaries\Win64\UE4Editor-TheTable-5513.dll 1
Error Failed to produce item: C:\Users\Documents\Unreal Projects\03_BuildingEscape\TheTable\Binaries\Win64\UE4Editor-TheTable-5513.dll TheTable C:\Users\Documents\Unreal Projects\03_BuildingEscape\TheTable\Intermediate\ProjectFiles\ERROR 1
Error MSB3075 The command ““C:\Program Files\Epic Games\UE_4.16\Engine\Build\BatchFiles\Build.bat” TheTableEditor Win64 Development “C:\Users\Documents\Unreal Projects\03_BuildingEscape\TheTable\TheTable.uproject” -waitmutex” exited with code 5. Please verify that you have sufficient rights to run this command. TheTable C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.MakeFile.Targets 44