Including prolog c++ libraries inside Unreal Engine

I’m using: SWI-Prolog version 9.2.4, Unreal Engine version 5.3, Visual Studio 2022 version 17.10.3

I want to add the prolog c++ SWI-cpp2.h header file to an Unreal Engine component

But when I try to do that I get compiling issues

My code looks like this:

#pragma warning(disable: 4800)
#include "Windows/MinWindows.h"
#include "Windows/AllowWindowsPlatformTypes.h"
THIRD_PARTY_INCLUDES_START
#include "SWI-cpp2.h"
THIRD_PARTY_INCLUDES_END
#include "Windows/HideWindowsPlatformTypes.h"
#include "SWIPrologComponent.generated.h"

I also tried, hoping to solve anything, this:

#pragma warning(disable: 4800)
#include "Windows/MinWindows.h"
#include "Windows/AllowWindowsPlatformTypes.h"
THIRD_PARTY_INCLUDES_START
#include "SWI-Stream.h"
#include "SWI-Prolog.h"
#include "SWI-cpp2.h"
THIRD_PARTY_INCLUDES_END
#include "Windows/HideWindowsPlatformTypes.h"
#include "SWIPrologComponent.generated.h"

my errors look like this:

\ThirdParty\SWIProlog\headers\SWI-Stream.h(70): error C2628: 'intptr_t' followed by 'int' is illegal. Did you forget a ';'?
...
\ThirdParty\SWIProlog\headers\SWI-cpp2.h(1042): error C2059: syntax error: '{'
...
\ThirdParty\SWIProlog\headers\SWI-cpp2.cpp(972): error C2660: 'PlStream::Sputw': function does not take 2 arguments
...

and many other similar errors that shouldn’t be there of course.
I understand this may not be the right place to discuss something like this, but if you can help me out understand the dynamics in order to compile these header files I might be able to research it on some unreal engine related discussion groups.

1 Like

I solved my issue by adding PublicDefinitions.Add("_SWI_CPP2_H"); inside the build.cs file of the unreal project. Still I don’t understand the implications of such a mistake.

1 Like

Another thing that can cause a problem is the version of C++ that the compiler supports.
I recently added some features to SWI-cpp2.h (which should be in the next development release), and got strange error messages from one package, until I specified -std=c++17 (or set(CMAKE_CXX_STANDARD 17)).

1 Like