Download

How do I add dynamic libraries to the engine / plugins?

I’ve seen wiki entries about exporting/importing individual functions, but for a large ThirdParty library, this simply isn’t an option.

How can I get a dynamic library linked in and usable in the engine source? I believe there is 0 documentation on this process.

Any help would be appreciated.

Generally, anything you want to add to the Engine needs to become a “module”.

Take a look in the Engine/Source/ThirdParty folder - any one of those is an external library, either dynamically or statically linked.

For example, SDL2 is a full featured framework and if you look at its SDL2.Build.cs you can see how it is setup to find and connect to include and lib folders for each supported platform:



public class SDL2 : ModuleRules
{
    public SDL2(TargetInfo Target)
    {
        Type = ModuleType.External;
...
string SDL2Path = UEBuildConfiguration.UEThirdPartySourceDirectory + "SDL2/SDL-gui-backend/";
string SDL2LibPath = SDL2Path + "lib/";
.....

PublicIncludePaths.Add(SDL2Path + "include");
....
PublicAdditionalLibraries.Add(SDL2LibPath + "Linux/" + Target.Architecture + "/libSDL2_fPIC.a");
....


Then somewhere in the Engine code, where you need this library (now a module), you would include a reference to it as a module name (in this case SDL2) in the Build.cs file.

For example, from Engine/Source/Runtime/Core/Core.Build.cs:



...
 else if ((Target.Platform == UnrealTargetPlatform.Linux))
{
    PublicIncludePaths.Add("Runtime/Core/Public/Linux");
    AddThirdPartyPrivateStaticDependencies(Target,
        "zlib",
        "jemalloc",
        "elftoolchain",
        "**SDL2**"
    );
...


And then in your code you would add your includes and call the library functions:

FromLinuxSplash.cpp:



...
#include "SDL.h"
#include "SDL_thread.h"
#include "SDL_timer.h"
...
// load splash .bmp image
GSplashScreenImage = SDL_LoadBMP(TCHAR_TO_UTF8(*GSplashPath));
...


Does that make sense?

Might feel like i’m necro digging posts, but we’re in 2017 and this post just saved my life. :smiley: