Build a UE4 compatible static lib in VS2013
Introduction
This is the first tutorial in a two (or maybe three) part series that will explain how to integrate libraries not built by UBT into your UE4 games or plugins. This tutorial will cover building of static libraries in VS2013, but most of this will also apply when building dynamic libraries.
We’re going to build the pugixml library, a small and lightweight XML processing library written in C++. I’ve chosen this library because it doesn’t have any dependencies, only consists of three source files, and is easy to configure, so we can focus on the details that are specifically relevant to Unreal Engine 4. The final VS2013 project is available on GitHub.
Configure pugixml
The library can be configured by editing pugiconfig.hpp
.
Unreal Engine 4 uses the Unicode character set by default (characters are represented by wchar_t
instead of char
), so lets enable Unicode support in pugixml
:
|
|
Usage of the STL is frowned upon in Unreal Engine 4 code because it comes with its own set of
standard-for-ue4 classes you should use instead. Third party libraries can still use the STL if
needed. pugixml
has the ability to use the STL for strings and streams, but it can also work
quite happily without it, so lets remove the STL dependency:
|
|
By default UBT will build projects with C++ exceptions disabled, it’s best to keep this setting
consistent across all the libraries that are linked into a game project. We can prevent pugixml
from throwing C++ exceptions like so:
|
|
Project Properties
Platforms
We’ll need to create 32-bit and 64-bit versions of the library. The 32-bit version will be used in shipping builds (by default), and the 64-bit version will be used in development editor builds. VS2013 sets up a 32-bit platform by default, so we just need to add the 64-bit platform to the project. To do so:
- Right-click on the project in the VS2013
Solution Explorer
, selectProperties
from the context menu, and open theConfiguration Manager
dialog: - Add a new platform:
- Select
x64
from the drop-down, and pressOK
:
General Properties
The naming convention and directory structure you use for the library binaries is entirely up to you, however, future tutorials may assume you’ve set things up as described here.
- Select
All Configurations
from theConfiguration
drop-down. - Select
Win32
from thePlatform
drop-down. - Set the following properties on the
Configuration Properties/General
page as indicated:Output Directory
:$(SolutionDir)Build\\
Intermediate Directory
:$(SolutionDir)Obj\\Win32\\$(Configuration)\\
Target Name
:$(ProjectName)-Win32-$(Configuration)
- Press the
Apply
button. - Select
x64
from thePlatform
drop-down. - Set the following properties under the
Configuration Properties/General
section as indicated:Output Directory
:$(SolutionDir)Build\\
Intermediate Directory
:$(SolutionDir)Obj\\Win64\\$(Configuration)\\
Target Name
:$(ProjectName)-Win64-$(Configuration)
- Press the
Apply
button. - Select
All Platforms
from thePlatform
drop-down. - Ensure that the
Character Set
property is set toUse Unicode Character Set
.
C/C++ Properties
- Ensure that
All Configurations
andAll Platforms
are still selected. - On the
Configuration Properties/Code Generation
page setEnable C++ Exceptions
toNo
, and press theApply
button. - On the
Configuration Properties/Language
page setEnable Run-Time Type Information
toNo
, and press theApply
button. - Return to the
Configuration Properties/Code Generation
page. - Select the
Debug
configuration, and ensureRuntime Library
is set toMulti-threaded Debug DLL (/MDd)
. - Select the
Release
configuration, and ensureRuntime Library
is set toMulti-threaded DLL (/MD)
Build
You can now quickly build all four variants of the library by selecting Build
->Batch Build...
from the main menu in VS2013.