Adding a Third Party Library with source files

Hi speedpacer, have you figured it out properly? Your solution is still to prebuild to use a static lib, I would like to include the source directly in the project.

Sorry, overreal, I haven’t had to go down that path.

Hi,

I am trying to add a third party library that contains required header and source files. So far, I have tried adding them to a plugin and to Engine’s third party folder (following this link), but both result in an identical issue.

In one of the header files, it contains

#include <FOLDER-NAME/header-name.h>

and to include these header files, I have to add them in Visual Studio through project properties > VC++ Directories > Include Directories > add in direct path to include folder. This method will ensure that I have the required folders included without changing the files in the provided library (it is not my library, so I can’t be sure when it will be updated). Should I generate visual studio project files through my project’s .uproject file, these includes that I add will go missing. I believe I should be adding these through a module’s build.cs, but apart from the following,

AddThirdPartyPrivateStaticDependencies
PublicIncludePaths
PrivateIncludePaths

I can’t seem to find another method that might include the .h files. I think changing the #include to use “” instead of <> might help, but apart from that, are there any other methods I can solve this issue?

I’m having the same problem. I’ve gone through every tutorial, looked at examples on github, and even tried hard-coding the paths but no third party libraries are working for me. I can get VS to recognize them, no problem. But when I try to add them to the Build.cs file, I either get errors that the files can’t be found or that there is something wrong with the files, like a missing comma, or “::”… been fighting with it for two days now. crazy.

Okay, I figured it out, at least at the project level. I was making it harder than it needed to be as usual. Here’s what I did to get it working.

  1. Created a ThirdParty path in my project’s root folder

  2. Created subfolders under the ThirdParty folder for my library, such as:

    D:/UnrealProjects/MyProject/ThirdParty/MyLibrary/include
    D:/UnrealProjects/MyProject/ThirdParty/MyLibrary/lib/x64

  3. Copied the header files from the library into the include folder, like so:

    D:/UnrealProjects/MyProject/ThirdParty/MyLibrary/include/Mylibrary/*.h

NOTE: the library and the project have to be compiled with the same version of VS or whatever compiler you’re using.

  1. Add the .lib and .dll files, etc. to the lib/x64 folder. Also add the .dll files to the MyProject/Binaries/Win64 folder.

  2. In your Build.cs file, add the following lines to point to your newly created header and library files (note you’re including the path for headers files and for libraries, it’s the libraries themselves):

    PublicIncludePaths.Add(“D:/UnrealProjects/MyProject/ThirdParty/MyLibrary/include”);
    PublicAdditionalLibraries.Add(“D:/UnrealProjects/MyProject/ThirdParty/MyLibrary/lib/x64/MyLibrary.lib”);

  3. Close VS and right-click on the UE .uproject file and click Generate Visual Studio Project files.

  4. Now you should be add open it back up and add your #include “MyLibrary/myheader.h”, and so on and everything should work. You shouldn’t have to modify the VS project settings.

I was trying to go through some tutorials that suggested some fancy directory tricks to find the relative path, which is obviously something you eventually want to do, but first you want to make sure you can get the libraries added to your project and compile everything and verify it all works. Being unfamiliar with C#, I think that’s where I was having trouble.

1 Like
  1. In your Build.cs file, add the following lines to point to your newly
    created header and library files …

Later you say

4…You shouldn’t have to modify the VS project settings.

Clear as mud. As you know, there are lots of xxx.Build.cs files within a project. Which Build.cs file are you talking about? I’m assuming you are talking myProject.Build.cs and not myThirdPartyLibrary.Build.cs, or something else?

And exactly how is changing myProject.Build.cs not modifying the VS project settings?

I know its been awhile, but can you (or anyone else) explain?

Yes, it has been a while. I’ll do my best.

By project settings, I meant Visual Studio settings, not the UE4 project settings. In other words, you shouldn’t have to go into your settings in the VS application menu. You should only have to modify the files I mentioned in your UE4 project. The OP mentioned having to “add them in Visual Studio through project properties > VC++ Directories > Include Directories > add in direct path to include folder”.

And you are correct. The Build.cs file you need to modify would be the game files in which you are adding the third party library. You’re letting your game know how to find the third party library. A typical third party library should have no need to be aware of your application, your UE4 game in this case.

1 Like

That makes sense. Many thanks.

for some reason this is not working!!

in D:/UnrealProjects/MyProject/ThirdParty/MyLibrary/MyLibrary.Build.cs

i wrote this PublicIncludePaths.Add(“D:/UnrealProjects/MyProject/ThirdParty/MyLibrary/include”);
i get compiler

fatal error C1083: Cannot open include file: ‘MyLibrary/MyHeader.h’: No such file or directory