# Complete Example of UELibrary setup + extending the API

**URL:** <https://forums.unrealengine.com/t/complete-example-of-uelibrary-setup-extending-the-api/1257170>\
**Category:** C++\
**Tags:** unreal-engine, CPP\
**Created:** [August 10, 2023, 9:31pm UTC](https://forums.unrealengine.com/t/complete-example-of-uelibrary-setup-extending-the-api/1257170 "2023-08-10T21:31:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaliasotMta](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/paliasotmta/32/731478_2.png) [@PaliasotMta](https://forums.unrealengine.com/u/PaliasotMta)\
**Post date:** [August 10, 2023, 9:31pm UTC](https://forums.unrealengine.com/t/complete-example-of-uelibrary-setup-extending-the-api/1257170/1 "2023-08-10T21:31:43Z")

</div>

# Complete Example of building and extending UELibrary

I’ve spent a lot of time figuring our how to set up UELibrary for my custom project. The [official documentation](https://docs.unrealengine.com/4.27/en-US/SharingAndReleasing/BuildAsALibrary/) is helpful but unfortunately incomplete. I’ve compiled all of my findings in one post + added an example on how you can extend the base API.

You can find the complete example [here](https://github.com/paliasotamta/UELibApp). I will outline the main points in this post:

1. Get the source code for Unreal Engine. Compile it in the **Development Editor** configuration.
2. Create a new Blank C++ Project. Let’s call it `UELibExtended`.
3. Modify the `UELibExtended.target.cs` file per official documentation. You must add UELibrary module as well.
4. Compile `UELibExtended` in **Development** configuration. It will produce `UELibExtended.lib` and `UELibExtended.dll`.
5. Create a new Win32 app and link it against `UELibExtended.lib`. You’ll need to reference the `UnrealEngine\Engine\Source\Runtime\UELibrary\Public\UELibraryAPI.h` header in your app.
6. When your project compiles copy `UELibExtended.dll` to the output directory.

To extend the base API you will need to create a new .h and .cpp file. Expose your functions using the `__declspec(dllexport)` syntax.

```C++
// .h file
#pragma once

#ifdef UELIBEXTENDED_LIBRARY_DLL_EXPORT
#define UELIBEXTENDEDLIBRARYAPI __declspec(dllexport)
#else
#define UELIBEXTENDEDLIBRARYAPI __declspec(dllimport)
#endif

extern "C"
{
    UELIBEXTENDEDLIBRARYAPI int UELibExtended_CountActors();
}

```

```C++
// .cpp file
#define UELIBEXTENDED_LIBRARY_DLL_EXPORT
#include "UELibExtendedApi.h"
#undef UELIBEXTENDED_LIBRARY_DLL_EXPORT

#include "EngineMinimal.h"

UELIBEXTENDEDLIBRARYAPI int UELibExtended_CountActors()
{
    if (!GEngine) {
        return 0;
    }

    for (const FWorldContext& Context : GEngine->GetWorldContexts())
    {
        if (Context.WorldType == EWorldType::Game) {
            return Context.World()->GetActorCount();
        }
    }
    return 0;
}

```

Compile your game in **Development** configuration and copy your .h file to include folder of your app.

---

<div class="post-metadata">

**Author:** ![garry0905](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@garry0905](https://forums.unrealengine.com/u/garry0905)\
**Post date:** [January 10, 2025, 4:18am UTC](https://forums.unrealengine.com/t/complete-example-of-uelibrary-setup-extending-the-api/1257170/2 "2025-01-10T04:18:08Z")

</div>

Hi, @PaliasotMta.  
I read your topic carefully and it was really helpful.  
I followed your guide, but when the Unreal source is deleted, my application that embeds Unreal Engine as a library crashes.  
What is the problem? Which dll files are missing?  
Is it not possible to use it without the source code? If so, why did Epic make this feature?
