maybe try include windows.h before common
Hello everyone,
I’m trying to embed chatscript in a project I’m working on. Chatscritpt 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?
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.
Could you compile this chatbot as a static library and then bring it in?
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…
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.
I solved the problem, here are the steps:
- Include the source files of the program you want to embed in the source folder of your Unreal project
- 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).
- Compile
In my case I had also to modify the source code to compile without errors.
I hope this could help!