-1

我有一些在 OpenGL 中工作的代码,现在我想使用 ImGui 为我的应用程序制作 GUI。

ImGui::CreateContext();当我试图通过包含一些头文件将ImGui 的一行代码复制到我的项目时ImGui,它持续了一百个错误(可能是由于链接)。

我正在使用 Ubuntu 18,我使用 Makefile 来编译整个项目

我在包括以下内容时遇到的一些错误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 ‘&lt;’ token
 template<typename T>
         ^
imgui/imgui.h:1280:5: error: unknown type name ‘ImVec2’
     ImVec2      WindowPadding;              // Padding within a window.

当我运行一些提供的示例时,它们运行良好。但是,当尝试将我的项目与 imgui 的单行代码合并时,最终会出现上面显示的错误。

4

1 回答 1

1

查看您遇到的错误类型,在我看来您正在尝试使用 C 编译器编译您的程序。但是,ImGui 是用 C++ 编写的。

例如:

imgui/imgui.h:204:1: error: unknown type name ‘namespace’; did you mean ‘isspace’?
 namespace ImGui
 ^~~~~~~~~

namespace是 C++ 保留关键字,您的编译器似乎无法识别它。

既然您提到您正在使用 MakeFile,请尝试在该文件中找到您正在使用的编译器。如果它显示 gcc,则将其替换为 g++。如果它正在使用 clang,请将其替换为 clang++。

于 2019-06-23T08:44:19.800 回答