Why can't I open include files?

Hello,

I have written a library that I want to use in my new UE4 project.

So I have added a include and lib folder to the /Engine/Source/ThirdParty/ folder (as described in this forum post UE4 AnswerHub

It all works fine when I generate the solution files there is effectively now a folder called “AWFramework” and it contains the cs build file.

Unfortunately when I try and include any header from my library then I get a compiler error saying that the header cannot be opened.

Now I am usually quite familiar with as to why the header cannot be found but with this unreal build system I am a bit confused.

here my CS build file

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;

public class AWFramework : ModuleRules
{
    public AWFramework(TargetInfo Target)
	{
		Type = ModuleType.External;

		if ((Target.Platform == UnrealTargetPlatform.Win64) ||
			(Target.Platform == UnrealTargetPlatform.Win32))
		{
            PublicIncludePaths.Add(UEBuildConfiguration.UEThirdPartyDirectory + "AWThirdParty/AWFramework/libAWFramework/Include");

            string LibraryPath = UEBuildConfiguration.UEThirdPartyDirectory + "AWThirdParty/AWFramework/libAWFramework/Lib/";
			string LibraryName = "libAWFramework";
			if (Target.Platform == UnrealTargetPlatform.Win64)
			{
				LibraryPath += "x64/";
			}
            else if (Target.Platform == UnrealTargetPlatform.Win32)
            {
                LibraryPath += "Win32/";
            }
			PublicLibraryPaths.Add(LibraryPath);
			PublicAdditionalLibraries.Add(LibraryName + ".lib");
		}
	}
}

I have triple checked that the header files are effectively at the right location and that my paths are correct, but the problem seems to be that if I reference my library header from within my game code, I need to specify something like this

#include "ThirdParty/AWThirdParty/AWFramework/libAWFramework/Include/AWFrameworkAll.h"

but the inside the library code itself it complains that it can’t find the header i.e.

#include "Networking/Sockets/ZMQ/AWZMQSocketBase.h"

but I can guarantee that as specified in the cs build file public path that I added , the file should be there

i.e.

UEBuildConfiguration.UEThirdPartyDirectory + “AWThirdParty/AWFramework/libAWFramework/Include” +
“Networking/Sockets/ZMQ/AWZMQSocketBase.h”

should exists.

so how do I make sure that the paths for files referenced from my unreal game are compatible with paths referenced by my library. As far as I know usually the paths are looked up depending on what additional path directories are being added to a project but I can’t seem to find any such thing in the UE4 project(in fact I believe that is what

PublicIncludePaths.Add

is supposed to do.

Any idea ?

In fact if I add

#include "ThirdParty/AWThirdParty/AWFramework/libAWFramework/Include/Networking/Sockets/ZMQ/AWZMQSocketBase.h"

instead of just

#include "Networking/Sockets/ZMQ/AWZMQSocketBase.h"

then it compiles but that is obviously wrong, the library needs to be agnostic of where it is being used.

any suggestion would be appreciated :slight_smile:

#Wiki Tutorial

Have you read this tutorial?

Is this what you need?

#Build.cs

public class UE4Magic : ModuleRules
{
    [Convenience Properties]
 
    [Constructor]
 
    public bool LoadBobsMagic(TargetInfo Target)
    {
        bool isLibrarySupported = false;
 
        if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))
        {
            isLibrarySupported = true;
 
            string PlatformString = (Target.Platform == UnrealTargetPlatform.Win64) ? "x64" : "x86";
            string LibrariesPath = Path.Combine(ThirdPartyPath, "BobsMagic", "Libraries");
 
            PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "BobsMagic." + PlatformString + ".lib")); 
        }
 
        if (isLibrarySupported)
        {
            // Include path
            PublicIncludePaths.Add( Path.Combine( ThirdPartyPath, "BobsMagic", "Includes" ) );
        }
 
        Definitions.Add(string.Format( "WITH_BOBS_MAGIC_BINDING={0}", isLibrarySupported ? 1 : 0 ) );
 
        return isLibrarySupported;
    }

I think if I compare the code you wrote with the cs file I posted above there isn’t much difference. Or can you see something missing ?

well I didnt write the code, but if you and Bob Gneu matched up that well, the rest of his tutorial should be helpful!

okay so I got finally my includes working. I had some issues with where I placed my third party code, I moved it and now at least it seems to get one step further.

I receive now a ton of errors where Unreal seems to dislike some data types that the library uses. I know the wiki page mentions that but it doesn’t mention how to fix it so here is the problem

    19>C:\Program Files (x86)\Windows Kits\8.1\include\shared\ws2def.h(245): error C2872: 'INT' : ambiguous symbolC:\Program Files (x86)\Windows Kits\8.1\include\shared\ws2def.h(245) : error C2872: 'INT' : ambiguous symbol
    19>  
    19>          could be 'C:\Program Files (x86)\Windows Kits\8.1\include\shared\minwindef.h(176) : int INT'
    19>          or       'I:\Projects\AWOnline\UnrealEngine\Engine\Source\Runtime\Core\Public\Core.h(509) : DoNotUseOldUE4Type::INT'

There is a very similar error about DWORD which unreal also doesn’t seem to like.

from the Core.h in unreal

/// Trick to prevent people from using old UE4 types (which are still defined in Windef.h on PC).
namespace DoNotUseOldUE4Type
{
	/// Used to cause compile errors through typedefs of unportable types. If unportable types 
	/// are really necessary please use the global scope operator to access it (i.e. :: INT). 
	/// Windows header file includes can be wrapped in #include "AllowWindowsPlatformTypes.h" 
	/// and #include "HideWindowsPlatformTypes.h"

looks like Epic indeed does some trickery here.

okay so here is the solution, anywhere you include a library header you can simply put the above mentioned wrappers around … i.e.

#include "AllowWindowsPlatformTypes.h"
#include "MyLibraryHeader.h" 
#include "HideWindowsPlatformTypes.h"

I would strongly suggest to create a header file that includes all relevant header files from any external library and just wrap the entire block and then just include that header file where you need have access to your library.

Where did you move it too to get this far? I have the same problem.

my project folders look like this
MyGame
- Binaries
- Build
- Config
- Content
- DerivedDataCache
- Intermediate
- Plugins
- Saved
- Source
- ThirdParty

hope that helps

Hey man, thx for all the help so far! I managed to get rid of the errors you mentioned here, but now i have problems using functions from the library. For example i have function that returns a string but i get link errors like this one:

error LNK2019: unresolved external symbol “public: static class std::basic_string,class std::allocator > __cdecl myTester::islibAlive(void)” (?islibAlive@myTester@@SA?AV?$basic_string@DU?$char_traits@D@std@@anonymous_user_e71e0d8a?$allocator@D@2@@std@@XZ) referenced in function “public: __cdecl AUtester::AUtester(class FPostConstructInitializeProperties const &)” (??0AUtester@@QEAA@AEBVFPostConstructInitializeProperties@@@Z)

Same thing with a function that returns a float value. If you could help in any way i would greatly appreciate it!

this usually means the library isn’t correctly references In the project or the library isn’t exporting the function (in case its a dll). Its not an unreal specific error.

1 Like

I really don’t get what the problem is, if i change for example the path to the lib in the build file it gives me errors, even when i use the a function from the lib in code it gives me no intellisense errors, the only error that it does give is the one i gave above. I really don’t get what am i doing wrong…

Hi
This topic is a bit old but I had the unresolved link problem and I solve it by compiling the dependancies in 64bits. Maybe your dependancies are 32bitss ??
btw, I am now trying to run my UE4 VC2013 project with a win32 settings (all my dependancies are not 64bits) but I have got a “fatal error C1083: Cannot open include file: ‘MyProject21.h’: No such file or directory”
Does anyone has any new thoughts about that ?