Getting lots of linker errors on linking cimgui

107 Views Asked by At

I followed the tutorial on the cimgui github and compiled cimgui. https://github.com/cimgui/cimgui

That gave me a cimgui.o file

But when I try to use it, I get lots of linker errors

I used: gcc main.o cimgui.o -o main

The linker errors start like this:

/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':

Also, if I use g++ instead of gcc in the above command, these errors disappear and everything links fine.

Isn't cimgui supposed to be used with gcc? What can I do to fix this?

Update

If I dynamically link with the compiled library i.e cimgui.so. The linker errors disappear, But I get undefined references for the backends

/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

How can I fix this now?

0

There are 0 best solutions below