How to Load .h Files From an External .lib?

I have added a library to our project (specifically the Thrift library). Everything appears to be good, however when compiling, the compiler can never find the header files in the libthrift.lib library.

To load the library, I have added the following in our build.cs file:



        string LibrariesPath = Path.Combine(ThirdPartyPath, "Thrift", "Libraries");
        PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "libthrift.lib"));
        PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "Thrift", "Includes"));


The libthrift.lib file itself is placed in ThirdParty/Thrift/Libraries/libthrift.lib

Now when we want to access the library, we include the header file (Thrift.h) which is present in the .lib, by doing this:

And that is where things fall apart. Anytime we try and load the header files in the lib, we just get errors, as such:

I’ve read so many tutorials and pieces of documentation on adding libraries to UE4 that I’m getting dizzy, and coming up with no solutions to this. Any pointers or thoughts or direction would be greatly appreciated - thank you!

The header files aren’t contained in the lib. You need to copy them from the sdk into your project. The .lib contains the implementation that the header files describe.

We did try putting the .h file from the source code in various places, however regardless of where it was or how we pointed to it, UE4 still refused to recognize that it existed.

You’re doing it mostly right.

  1. Copy lib and includes into your project source tree
  2. Add path containing the .h file to PublicIncludePaths
  3. Add library to PublicAdditionalLibraries
  4. Regenerate visual studio solution
  5. Include Thrift.h this way:
    #include “Thrift.h”

not this way
#include <Thrift/Thrift.h>

following the wiki page, i am trying to include external libraries (C++) to UE4 with build.cs and here is my code and wiki page link:

A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums

the wiki page doesn’t really say that much, or maybe it doesn’t need that much, but it fails to compile.
so if anyone has any idea, i would appreciate the help.
here are the codes and errors:

The first error there should be a big help - “Cannot convert from ReadOnlyTargetRules to TargetInfo”. Try changing line 37 from “public bool LoadTcAdsDll(TargetInfo Target)” to “public bool LoadTcAdsDll(ReadOnlyTargetRules Target)”.

That looks like it would probably clear up your build errors. You should be careful in that it looks like you bulk copy/pasted from the example - this is going to try to build a LIB by inserting the platform name in there too, so you had better have files called “TcAdsDllx86.lib” and “TcAdsDllx64.lib” (the + PlatformString bit from line 54). Also, you have a “PublicIncludePaths.Add()” call on line 60, but you might also need a “PublicLibraryPaths.Add()” call for the LIB file.