# Embedding a C++ program in a game project

**URL:** <https://forums.unrealengine.com/t/embedding-a-c-program-in-a-game-project/348817>\
**Category:** C++\
**Tags:** unreal-engine, UE4, CPP, question\
**Created:** [February 26, 2016, 11:11pm UTC](https://forums.unrealengine.com/t/embedding-a-c-program-in-a-game-project/348817 "2016-02-26T23:11:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_1fb002ad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1fb002ad](https://forums.unrealengine.com/u/anonymous_user_1fb002ad)\
**Post date:** [February 26, 2016, 11:11pm UTC](https://forums.unrealengine.com/t/embedding-a-c-program-in-a-game-project/348817/1 "2016-02-26T23:11:38Z")

</div>

Hello everyone,  
I’m trying to embed chatscript in a project I’m working on. [Chatscritpt](https://sourceforge.net/projects/chatscript/) is an open source chatbot C++ program, but it’s meant also to be embedded in bigger applications.

First of all I assured myself that it was compilable with vs2015 (Chatbot is shipped with a vs2010 project) and it is.  
Then I just added the source code (actually the whole folder of chatcript) in the game directory inside the source folder of my unreal project, and that’s here were my problems started.

Thanks to the complaints of the compiler and google I discovered that I had to wrap all the windows related include with:

```
#include "AllowWindowsPlatformTypes.h" 
#include "HideWindowsPlatformTypes.h"

```

And I had to include the chatcript common.h also in the unreal files I have (for now just an Actor class, and the main class of the project).  
Now though I’m stuck with these errors:

```
1> Compiling game modules for hot reload
1> Performing 41 actions (4 in parallel)
1> PCH.common.h.cpp
1>C:\Program Files (x86)\Windows Kits\8.1\include\shared\minwindef.h(156): error C2039: 'DWORD': is not a member of '`global namespace''
1>C:\Program Files (x86)\Windows Kits\8.1\include\shared\minwindef.h(160): error C2039: 'FLOAT': is not a member of '`global namespace''
1>C:\Program Files (x86)\Windows Kits\8.1\include\shared\minwindef.h(176): error C2039: 'INT': is not a member of '`global namespace''
1>C:\Program Files (x86)\Windows Kits\8.1\include\shared\minwindef.h(177): error C2039: 'UINT': is not a member of '`global namespace''
1>C:\Program Files (x86)\Windows Kits\8.1\include\um\winnt.h(147): fatal error C1189: #error: "No Target Architecture"
1> -------- End Detailed Actions Stats -----------------------------------------------------------
1>ERROR : UBT error : Failed to produce item: [project path]

```

I’m new to C++ (but not new to programming, I know Java and C#), I think there is still some problem with some windows include but this time google didn’t help me, and I have no clue. Some of you have some suggestions?

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [February 26, 2016, 11:35pm UTC](https://forums.unrealengine.com/t/embedding-a-c-program-in-a-game-project/348817/2 "2016-02-26T23:35:01Z")

</div>

maybe try include windows.h before common

---

<div class="post-metadata">

**Author:** ![Bino](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Bino](https://forums.unrealengine.com/u/Bino)\
**Post date:** [February 27, 2016, 12:14am UTC](https://forums.unrealengine.com/t/embedding-a-c-program-in-a-game-project/348817/3 "2016-02-27T00:14:19Z")

</div>

Could you compile this chatbot as a static library and then bring it in?

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1fb002ad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1fb002ad](https://forums.unrealengine.com/u/anonymous_user_1fb002ad)\
**Post date:** [February 27, 2016, 12:18am UTC](https://forums.unrealengine.com/t/embedding-a-c-program-in-a-game-project/348817/4 "2016-02-27T00:18:17Z")

</div>

Unfortunatly I cannot do that the compiler says I need common.h as first include:

```
EXEC : error : All source files in module "unreal_dontmakelove" must include the same precompiled header first. Currently "[...]\Source\unreal_dontmakelove\ChatScript-6.2.b\SRC\common.h" is included by most of the source files. The following source files are not including "[...]\Source\unreal_dontmakelove\ChatScript-6.2.b\SRC\common.h" as their first include:
    1>
    1> [...]\Source\unreal_dontmakelove\ChatbotEngineCore.cpp (including C:\Program Files (x86)\Epic Games\4.10\Engine\Source\Runtime\Core\Public\Windows\AllowWindowsPlatformTypes.h)
    1> [...]\Source\unreal_dontmakelove\unreal_dontmakelove.cpp (including C:\Program Files (x86)\Epic Games\4.10\Engine\Source\Runtime\Core\Public\Windows\AllowWindowsPlatformTypes.h)

```

By the way windows.h is included inside common.h I tried nonetheless to include it again as second in the unreal files, but the compiler still gives the same errors.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1fb002ad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1fb002ad](https://forums.unrealengine.com/u/anonymous_user_1fb002ad)\
**Post date:** [February 27, 2016, 9:10pm UTC](https://forums.unrealengine.com/t/embedding-a-c-program-in-a-game-project/348817/5 "2016-02-27T21:10:51Z")

</div>

Thank you, I followed your suggestion, and now I can compile the project, though I’m unable to use ChatScript. According to the documentation:

> To embed CS within a client, you need to perform two calls. To call these routines, your code will need a predeclaration of these routines. The first is

> `InitSystem(int argc, char * argv[],char* unchangedPath, char* readablePath, char* writeablePath, USERFILESYSTEM* userfiles)`

> where you pass in various command line parameters to control things like logging or memory usage. Only the first two parameters are required, the remainder being optional and defaulted to NULL.

I predeclared the methods, but I cannot use them. USERFILESYSTEM is not recognized and if I include the common.h (wrapped with the windows includes) to be able to use it than I got an internal error of the compiler:

```
[...]\Source\unreal_dontmakelove\ChatbotEngineCore.cpp(9): fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'msc1.cpp', line 1393)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
1> INTERNAL COMPILER ERROR in 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\cl.exe'
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information

```

I didn’t imagine that could have been so complicated embedding external C++ code in Unreal…

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1fb002ad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1fb002ad](https://forums.unrealengine.com/u/anonymous_user_1fb002ad)\
**Post date:** [February 27, 2016, 9:40pm UTC](https://forums.unrealengine.com/t/embedding-a-c-program-in-a-game-project/348817/6 "2016-02-27T21:40:52Z")

</div>

I did some other try. I included directly the common.h and wrapped the windows includes that were inside the common.h and now I have again the original problem (the global namespace one).

So basically I cannot include the common.h, but without it I don’t know how to call the routines I need.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1fb002ad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1fb002ad](https://forums.unrealengine.com/u/anonymous_user_1fb002ad)\
**Post date:** [April 5, 2016, 6:28pm UTC](https://forums.unrealengine.com/t/embedding-a-c-program-in-a-game-project/348817/7 "2016-04-05T18:28:15Z")

</div>

I solved the problem, here are the steps:

1. Include the source files of the program you want to embed in the source folder of your Unreal project
2. After you’re sure that the files you added appear in the solution explorer of Visual Studio (refreshing the VS project should be enough) you have to include the header file of your project in each of them (at the beginning).
3. Compile 🙂

In my case I had also to modify the source code to compile without errors.  
I hope this could help!
