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.
-
Created a ThirdParty path in my projectâs root folder
-
Created subfolders under the ThirdParty folder for my library, such as:
D:/UnrealProjects/MyProject/ThirdParty/MyLibrary/include
D:/UnrealProjects/MyProject/ThirdParty/MyLibrary/lib/x64 -
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.
-
Add the .lib and .dll files, etc. to the lib/x64 folder. Also add the .dll files to the MyProject/Binaries/Win64 folder.
-
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â); -
Close VS and right-click on the UE .uproject file and click Generate Visual Studio Project files.
-
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.
- 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.
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
I found this piece of documentation for unreal 4, it should work the same in later versions.
However Iâm still having troubles adding some old school cpp header files. Does anyone know how to do it, Iâm talking about swi-cpp2.h, although itâs âregurarlyâ updated, I seem to have many troubles including it. Iâve added all the required dependencies and I still get compilation errors on the swi-cpp2.cpp file. These errors are about syntax but on a separate cpp project (not unreal) it works fine