# Using 3rd party libraries in cross-platform way

**URL:** <https://forums.unrealengine.com/t/using-3rd-party-libraries-in-cross-platform-way/374802>\
**Category:** Platform & Builds\
**Tags:** libraries, Third-Party, build, unreal-engine, CPP, question\
**Created:** [October 29, 2016, 10:34am UTC](https://forums.unrealengine.com/t/using-3rd-party-libraries-in-cross-platform-way/374802 "2016-10-29T10:34:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_24cff47d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_24cff47d](https://forums.unrealengine.com/u/anonymous_user_24cff47d)\
**Post date:** [October 29, 2016, 10:34am UTC](https://forums.unrealengine.com/t/using-3rd-party-libraries-in-cross-platform-way/374802/1 "2016-10-29T10:34:27Z")

</div>

It looks like using 3rd party libraries involves building Windows DLLs and lib files and linking to them. However I need to generate Windows as well Linux builds of the game (my library is also portable cross-platform). What is the best way to use 3rd party libraries in cross-platform way in Unreal? Previously I thought I can just drop-in the code for the library in a folder, add include file and just compile. However doing this gave me an error related to pre-compiled header:

```
Info ERROR: The first include statement in source file 'xxx.cpp' is trying to include the file 'stdio.h' as the precompiled header, but that file could not be located in any of the module's include search paths.

```

The usual suggestions such as changing order of the header didn’t worked. Any suggestions would be helpful.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_24cff47d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_24cff47d](https://forums.unrealengine.com/u/anonymous_user_24cff47d)\
**Post date:** [October 30, 2016, 9:55am UTC](https://forums.unrealengine.com/t/using-3rd-party-libraries-in-cross-platform-way/374802/2 "2016-10-30T09:55:12Z")

</div>

It seems the easiest way is to use compiled libraries with Unreal as opposed to dropping in the source code of the library in the Unreal project. I followed instructions at below page (with few changes) to use compiled version:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

Changes required in above instructions:

1. Use Multithreaded Dynamic Library as opposed to Static Library setting. If you don’t do this then you will get error such as `error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj` and `error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MD_DynamicDebug' in program.obj`
2. Make sure you don’t have \_CONSOLE or \_DEBUG macros defined in Release build (see C/C++ \> Preprocessors tab).
3. Build both Release and Debug versions of library and put them in Libraries folder. Below is the code in my MyUEProject.Build.cs

**Code:**

```
using UnrealBuildTool;
using System.IO;
public class FlyingTest : ModuleRules
{
	private string ModulePath
	{
		get { return ModuleDirectory; }
	}
		 
	private string ThirdPartyPath
	{
		get { return Path.GetFullPath( Path.Combine( ModulePath, "ThirdParty/" ) ); }
	}
	
	public FlyingTest(TargetInfo Target)
	{
		UEBuildConfiguration.bForceEnableExceptions = true;
		PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "RenderCore" });
		
		LoadThirdPartyLibrary(Target, "MavLinkCom");
	}
	
	public bool LoadThirdPartyLibrary(TargetInfo Target, string LibName)
	{
		bool isLibrarySupported = false;

		string LibrariesPath = Path.Combine(ThirdPartyPath, LibName, "Libraries");
		string PlatformString = (Target.Platform == UnrealTargetPlatform.Win64) ? "x64" : "x86";
		string ConfigurationString = (Target.Configuration == UnrealTargetConfiguration.Debug) ? "Debug" : "Release";

		if (Target.Platform == UnrealTargetPlatform.Win64)
		{
			isLibrarySupported = true;
 
			PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, PlatformString, ConfigurationString, LibName + ".lib")); 
		}
 
		if (isLibrarySupported)
		{
			// Include path
			PublicIncludePaths.Add( Path.Combine( ThirdPartyPath, LibName, "Includes" ) );
		}
 
		Definitions.Add(string.Format( "WITH_" + LibName.ToUpper() + "_BINDING={0}", isLibrarySupported ? 1 : 0 ) );
 
		return isLibrarySupported;
	}	
}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_24cff47d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_24cff47d](https://forums.unrealengine.com/u/anonymous_user_24cff47d)\
**Post date:** [November 22, 2016, 4:02am UTC](https://forums.unrealengine.com/t/using-3rd-party-libraries-in-cross-platform-way/374802/3 "2016-11-22T04:02:01Z")

</div>

Just to follow up… if you have C++ header-only library that you want to drop in to your game project then easiest way is to create folder Source \> ThirdPary \> MyHeaderOnlyLib \> includes and then drop all your files in there. You can then include these files in UE4 C++ code as usual:

```
#include "ThirdParty/MyHeaderOnlyLib/include/MyLib.hpp"

```
