r/unrealengine 18d ago

Third party library (source-code) in custom plugin Solved

Hello everyone,

I am new to Unreal Engine and C++ in particular - and since 2-3 days I am struggling to integrate a third-party library into a custom plugin (blueprint library) that I want to add. Here's the gist of it:

So I've set up a Project in Unreal Engine 5.3. Basically it'll be a text adventure. In this project, I figured that I want to use some c++ libraries - mainly "liboai". Therefore, I decided to create a new Plugin, that I could maybe release to fab in the future. I downloaded and installed Visual Studio 2022 + the unreal tools and then I selected "Edit -> Plugins -> Add" to create a new Plugin in my Project.

I downloaded "liboai" from github and put it into the MyGame/Plugins/MyPlugin/Source/liboai. Then I added the folder to my PublicIncludePaths with "Path.Combine(ModuleDirectory, "../liboai/include/")".

Here comes the issue I am currently facing:
liboai itself uses curl and nlohmann-json. I downloaded and installed vcpkg executed "vcpkg integrate install", and ran "vcpkg install curl" and "vcpkg install nlohmann-json". I added the vcpkg.json and the vcpkg-configuration.json file to the Plugins root folder listing the dependencies to curl and nlohmann-json.

I did a right-click on my MyGame Project File and selected "Create Visual Studio Project Files" and re-started visual studio. But still, when I try to rebuild my solution it fails because it can not find curl. Navigating into liboai.h, I can also see the #include statement marked with a red line, and I can not ctrl+click to navigate to "curl/curl.h".

I then added the vcpkg folders to my PublicIncludePaths and to PublicAdditionalLibraries.
string sVcpkgIncludePath = "C:/Users/Moe/Documents/GitHub/vcpkg/installed/x64-windows/include";
string sVcpkgLibraryPath = "C:/Users/Moe/Documents/GitHub/vcpkg/installed/x64-windows/lib";
[...]
PublicIncludePaths.AddRange( new string[] {
[...]
sVcpkgIncludePath });
[...]
PublicAdditionalLibraries.Add(Path.Combine(sVcpkgLibraryPath, "libcurl.lib"));

In a new Console Application, I can do #include "curl/curl.h" without a problem. I can then ctrl+click in visual studio on the include name and it navigates me to the include file. I can also build a console application with curl.

So my question is: what am I doing wrong? I find this whole thing so complicated, I can not wrap my head around why it's working in a new console application, but not in my unreal plugin. I've tried so many things with environment variables, rebuilding solution, cleanin the solution, creating a new plugin all over, trying to find different settings in both visual studio and unreal... I feel very lost and could need some guidance.

Maybe I have a wrong understanding of how to include 3rd party libraries in my Plugin. I am coming from Python, so I am used to a very abstract package management where I can just expect the user to "pip install libraryXYZ" and everything works. I think I dont want to create a custom module for curl and all the other stuff that liboai uses. I feel like that defeats the whole purpose of including packages. But maybe thats just my bad understanding.

I think my Unreal Engine and Visual Studio are using MSBuild, because I did not change it to Cmake explicitly. I would appreciate any help. Let me know if you need more information!

Thanks everyone

3 Upvotes

2

u/botman 18d ago

Epic already has libcurl (version 8.4.0) in EngineSourceThirdPartylibcurl

0

u/BeanjaminBuxbaum 18d ago

Ok that's awesome, so please let's imagine it wouldn't be included or I'd be talking about a different library like the nlohmann-json. I am having a really hard time including those packages installed with vcpkg in my unreal plugin. Is it so uncommon? 

2

u/botman 18d ago

In your plugin's .Build.cs file just add...
AddEngineThirdPartyPrivateStaticDependencies(Target, "libcurl");

See C:Program FilesEpic GamesUE_5.4EngineSourceDeveloperDerivedDataCacheDerivedDataCache.Build.cs as an example.

It is not common for people to add their own external libraries. It can be done, but it usually requires more experience with the engine to do so.

1

u/BeanjaminBuxbaum 18d ago

Thank you so much for you input.

First, I don't understand why people downvote my reply. Yes, I can include libcurl a different way - and I would problably be able to use curl in my own plugin using this already provided library. But that does not solve my problem, because liboai is using curl like I described: by #include-ing "curl/curl.h". I could now go ahead and alter the liboai files, but that is exactly not what I want. I could also just copy curl and nlohmann into my plugin folder like I did with liboai. I assume that would work as well. But my question was more about how to include those vcpkg-installed libraries in my plugin.

Would you be so kind to elaborate on the "requires more experience with the engine to do so"-part? Because I would like to work out what knowledge I am exactly missing to make this seemingly simple thing happen: 1) install package with vcpkg, 2) use this package with my plugin (blueprint library).

Also please kindly explain "it is not common for people to add their own external libraries" - because I dont understand how this is not a thing? Are people always writing everything from scratch? That's what libraries are for, no?

again, I am happy for any insight, because I am not coming from the C++ world, and this is my first project in unreal.. so I dont get why visual studio cant just "understand" that I already installed libraryXYZ with vcpkg and just use those .h and .cpp files when I include them.

1

u/botman 18d ago

I don't think Unreal supports vcpkg. Unreal has it's own build tool for compiling code called UnrealBuildTool (UBT). UBT is the one that runs the C++ compiler. Code is not being compiled directly by Visual Studio. So you need to understand how UBT expects third party libraries to be set up in order to use them. That's what I meant about "requires more experience with the engine". You can look at some of the examples of third party libraries in the Engine/Source/ThirdParty folder (like libcurl) to see how some of them are set up.

1

u/BeanjaminBuxbaum 18d ago

I think I begin to understand; much appreciated. So my understanding from what you wrote is that the reason visual studio behaves differently (the Console Application vs. MyGame Solution) already during Development, is because it relies on the UBT when editing my game/plugin files, right? So when I write #include in my plugin source code, visual studio will "ask" the UBT what folders it's supposed to look at? ...And to make UBT aware of a folder, I just add in the build.cs file? - whereas in my console application visual studio does not rely on the UBT and can do its own magic (with msbuild or whatever) to figure out where to search? So that's the whole reason i can not include / ctrl+click it?

But then again, I added those vcpkg install paths to my build.cs file. I assumed it would do exactly that! Tell unreal engine/ubt during compile time where to find this stuff.. but it doesnt seem to work as expected - is it maybe a problem with absolute paths or something?

1

u/BeanjaminBuxbaum 18d ago

I think I solved it at least partially. For whatever reason I had to create the visual studio files again by right clicking on my .uproject file after deleting the DerivedDataCache and Intermediate and Binaries folder. Thanks everyone.