I have some code working in OpenGL and now I would like to use ImGui to make a GUI for my application.
When I tried to copy a one line code of ImGui to my project ImGui::CreateContext();
by including some of the header files of ImGui
, it lasted by a hundred errors (due maybe to linking).
I'm working with Ubuntu 18 and I use a Makefile to compile the whole project
Some of the errors that I got when including imgui.h
:
imgui/imgui.h:153:39: error: unknown type name ‘ImGuiInputTextCallbackData’; did you mean ‘ImGuiInputTextFlags’?
typedef int (*ImGuiInputTextCallback)(ImGuiInputTextCallbackData *data);
^~~~~~~~~~~~~~~~~~~~~~~~~~
ImGuiInputTextFlags
imgui/imgui.h:154:35: error: unknown type name ‘ImGuiSizeCallbackData’
typedef void (*ImGuiSizeCallback)(ImGuiSizeCallbackData* data);
^~~~~~~~~~~~~~~~~~~~~
imgui/imgui.h:179:5: error: expected specifier-qualifier-list before ‘ImVec2’
ImVec2() { x = y = 0.0f; }
^~~~~~
imgui/imgui.h:192:5: error: expected specifier-qualifier-list before ‘ImVec4’
ImVec4() { x = y = z = w = 0.0f; }
^~~~~~
imgui/imgui.h:204:1: error: unknown type name ‘namespace’; did you mean ‘isspace’?
namespace ImGui
^~~~~~~~~
isspace
imgui/imgui.h:205:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
{
^
In file included from window.c:23:0:
imgui/imgui.h:1200:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘new’
inline void* operator new(size_t, ImNewDummy, void* ptr) { return ptr; }
^~~
imgui/imgui.h:1201:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘delete’
inline void operator delete(void*, ImNewDummy, void*) {} // This is only required so we can use the symmetrical new()
^~~~~~
imgui/imgui.h:1206:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
template<typename T> void IM_DELETE(T* p) { if (p) { p->~T(); ImGui::MemFree(p); } }
^
imgui/imgui.h:1217:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
template<typename T>
^
imgui/imgui.h:1280:5: error: unknown type name ‘ImVec2’
ImVec2 WindowPadding; // Padding within a window.
When I run some examples that are provided, they work perfectly. However, when trying to merge my project with a single line of code of imgui, it ends up with the errors shown above.
Looking at the kind of errors you are getting, it seems to me that you are trying to compile your program with a C compiler. However, ImGui is written in C++.
For, example:
imgui/imgui.h:204:1: error: unknown type name ‘namespace’; did you mean ‘isspace’?
namespace ImGui
^~~~~~~~~
namespace
is a C++ reserved keyword and your compiler doesn't seem to recognize it as such.
Since you mentioned that you are using MakeFile, try to find in that file what compiler you are using. If it says gcc, replace it by g++. If it's using clang, replace it by clang++.