Skip to content

Linking static and dynamic C libraries

Thomas edited this page Jan 31, 2015 · 26 revisions

I: Create a "ThirdParty" folder in your UE4 project's source folder.
Step1

II: In the "ThirdParty" folder, create a folder that determines your libary's name.
Step2

III: In the library folder, create a C# build file - the name is the same as the folder's, the extension is ".build.cs".
Step3

IV: Create the build file for the libarary (see main aspects of the build file in the code comments) - See code block containing the build file at the bottom
Step4

V: Add the library to your project's build file
Step5

C# Build File Code

/* Copyright 1998-2014 Epic Games, Inc. All Rights Reserved. */
using UnrealBuildTool;

public class K4WLib : ModuleRules
{
    public K4WLib(TargetInfo Target)
	{
		Type = ModuleType.External;
		
		/* Path to the Kinect V2 SDK read from environment variable */
        string SDKDIR = Utils.ResolveEnvironmentVariable("%KINECTSDK20_DIR%");
		/* Change path format from Windows backslashes to forward slashes */
        SDKDIR = SDKDIR.Replace("\\", "/");

		if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))
		{
			/* Add the SDK's include folder to the Unreal include paths. */
            PublicIncludePaths.Add(SDKDIR+"inc/");
			
			/* Use the fitting plattform suffix */
            string PlatformPath =  (Target.Platform == UnrealTargetPlatform.Win64) ? "x64/" : "x86/";
			/* Path to the SDK's lib folder*/
            string LibPath = SDKDIR+"Lib/"+PlatformPath;
			
			/* Add the Kinect library path to Unreal's libarary paths */
            PublicLibraryPaths.Add(LibPath);
			/* Add the needed static library */
            PublicAdditionalLibraries.Add("Kinect20.lib");

			/* Path to the SDK's redistributable directory */
            string redistPath = SDKDIR + "Redist/";
			/* Add the VisualGestureBuilder dynamic library to Unreal's DLLs to be loaded. */
            PublicDelayLoadDLLs.AddRange(new string[] { redistPath+"VGB/"+PlatformPath+"Kinect20.VisualGestureBuilder.dll" });
		}
	}
}