我按照cimgui github上的教程编译了cimgui。 https://github.com/cimgui/cimgui
这给了我一个
cimgui.o
文件
但是当我尝试使用它时,我收到很多链接器错误
我用过:
gcc main.o cimgui.o -o main
链接器错误是这样开始的:
/usr/bin/ld: cimgui.o: in function `void IM_DELETE<ImDrawList>(ImDrawList*) [clone .part.0]':
cimgui.cpp:(.text+0xc5): undefined reference to `ImDrawList::_ClearFreeMemory()'
/usr/bin/ld: cimgui.cpp:(.text+0xd1): undefined reference to `ImDrawListSplitter::ClearFreeMemory()'
/usr/bin/ld: cimgui.cpp:(.text+0xe2): undefined reference to `ImGui::MemFree(void*)'
/usr/bin/ld: cimgui.cpp:(.text+0xf3): undefined reference to `ImGui::MemFree(void*)'
/usr/bin/ld: cimgui.cpp:(.text+0x101): undefined reference to `ImGui::MemFree(void*)'
/usr/bin/ld: cimgui.cpp:(.text+0x10f): undefined reference to `ImGui::MemFree(void*)'
/usr/bin/ld: cimgui.cpp:(.text+0x11d): undefined reference to `ImGui::MemFree(void*)'
/usr/bin/ld: cimgui.o:cimgui.cpp:(.text+0x12b): more undefined references to `ImGui::MemFree(void*)' follow
/usr/bin/ld: cimgui.o: in function `ImVec2_ImVec2_Nil':
cimgui.cpp:(.text+0x15e): undefined reference to `ImGui::MemAlloc(unsigned long)'
/usr/bin/ld: cimgui.o: in function `ImVec2_ImVec2_Float':
此外,如果我在上面的命令中使用
g++
而不是 gcc
,这些错误就会消失,并且一切都会正常链接。
cimgui 不是应该和
gcc
一起使用吗?
我可以做什么来解决这个问题?
如果我动态链接已编译的库,即
cimgui.so
。链接器错误消失了,但我得到了后端未定义的引用
/usr/bin/ld: /tmp/ccUuGQoj.o: in function `main':
main.c:(.text+0x175): undefined reference to `ImGui_ImplGlfw_InitForOpenGL'
/usr/bin/ld: main.c:(.text+0x186): undefined reference to `ImGui_ImplOpenGL3_Init'
/usr/bin/ld: main.c:(.text+0x1e4): undefined reference to `ImGui_ImplOpenGL3_NewFrame'
/usr/bin/ld: main.c:(.text+0x1ee): undefined reference to `ImGui_ImplGlfw_NewFrame'
/usr/bin/ld: main.c:(.text+0x477): undefined reference to `ImGui_ImplOpenGL3_RenderDrawData'
/usr/bin/ld: main.c:(.text+0x4df): undefined reference to `ImGui_ImplOpenGL3_Shutdown'
/usr/bin/ld: main.c:(.text+0x4e9): undefined reference to `ImGui_ImplGlfw_Shutdown'
collect2: error: ld returned 1 exit status
我现在该如何解决这个问题?
您还需要链接已编译的库 cimgui_glfw.so。 看项目中的这个例子cimgui
您可以从链接编译示例并将 lib cimgui_glfw.so 复制到您的项目中。
希望回复还不算太晚。