# How to modify build file to copy DLLs to binaries?

**URL:** <https://forums.unrealengine.com/t/how-to-modify-build-file-to-copy-dlls-to-binaries/353587>\
**Category:** C++\
**Tags:** packaging-and-cookin, unreal-engine, question, CPP\
**Created:** [April 9, 2016, 11:51pm UTC](https://forums.unrealengine.com/t/how-to-modify-build-file-to-copy-dlls-to-binaries/353587 "2016-04-09T23:51:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xarol](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Xarol](https://forums.unrealengine.com/u/Xarol)\
**Post date:** [April 9, 2016, 11:51pm UTC](https://forums.unrealengine.com/t/how-to-modify-build-file-to-copy-dlls-to-binaries/353587/1 "2016-04-09T23:51:34Z")

</div>

How does one modify the build file to copy DLLs to the Binaries folder?

I have tried adding

```
    RuntimeDependencies.Add(new RuntimeDependency(Path.Combine(Path.Combine(LibPath, <mydll>))));

```

but that copies things that start in the ThirdParty folder into another ThirdParty folder when I package a game for shipping. How do I make things in the ThirdParty folder in the source tree show up in the Binaries folder when the game is packaged?

The reason I would like DLLs to show up in the Binaries directory is so that they are automatically found at runtime. I tried using something like

```
FPlatformProcess::GetDllHandle(myPath);

```

but that crashed the game even though I verified myPath existed.

Thanks,  
-X

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2df21e76](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2df21e76](https://forums.unrealengine.com/u/anonymous_user_2df21e76)\
**Post date:** [April 10, 2016, 12:21am UTC](https://forums.unrealengine.com/t/how-to-modify-build-file-to-copy-dlls-to-binaries/353587/2 "2016-04-10T00:21:38Z")

</div>

This is how I do it. Each Third Party lib uses a Build.cs file and the module is added as dependency in the main project’s Build.cs file.

Here is how the hypothetical module “YourLib” works.

YourLib.Build.cs:

```
using System;
using System.IO;
using UnrealBuildTool;

public class YourLib : ModuleRules
{
    public string GetUProjectPath()
    {
		//Change this according to your module's relative location to your project file. If there is any better way to do this I'm interested!
		//Assuming Source/ThirdParty/YourLib/
        return Directory.GetParent(ModuleDirectory).Parent.Parent.ToString();
    }

    private void CopyToBinaries(string Filepath, TargetInfo Target)
    {
        string binariesDir = Path.Combine(GetUProjectPath(), "Binaries", Target.Platform.ToString());
        string filename = Path.GetFileName(Filepath);

        if (!Directory.Exists(binariesDir))
            Directory.CreateDirectory(binariesDir);

        if (!File.Exists(Path.Combine(binariesDir, filename)))
            File.Copy(Filepath, Path.Combine(binariesDir, filename), true);
    }

    public YourLib(TargetInfo Target)
	{
		Type = ModuleType.External;

		Definitions.Add("WITH_YOURLIB=1");

		// Compile and link with YOURLIB

		PublicIncludePaths.Add(ModuleDirectory + "/include");
		PublicAdditionalLibraries.Add(ModuleDirectory + "/lib/YourLib.lib");
		CopyToBinaries(ModuleDirectory + "/lib/YourLib.dll", Target);
	}
}

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Xarol](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Xarol](https://forums.unrealengine.com/u/Xarol)\
**Post date:** [April 24, 2016, 7:20pm UTC](https://forums.unrealengine.com/t/how-to-modify-build-file-to-copy-dlls-to-binaries/353587/3 "2016-04-24T19:20:11Z")

</div>

Thanks for this answer. Very helpful. Sorry for slow response as I was on vacation. Thanks to for accepting on my behalf.
