imgui icon indicating copy to clipboard operation
imgui copied to clipboard

Dear ImGui for pure C lang

Open mohammed777200 opened this issue 8 months ago • 7 comments

Version/Branch of Dear ImGui:

Version 1.XX, Branch: XXX (master/docking/etc.)

Back-ends:

imgui_impl_XXX.cpp + imgui_impl_XXX.cpp

Compiler, OS:

gcc, clang

Full config/build information:

Dear developers, I'm doing my efforts to translate Dear ImGui from C++ into C language, is there any suggestions or advises to keep up with this.

Thank y'all!

Details:

My Issue/Question:

XXX (please provide as much context as possible)

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

// Here's some code anyone can copy and paste to reproduce your issue
ImGui::Begin("Example Bug");
MoreCodeToExplainMyIssue();
ImGui::End();

mohammed777200 avatar Apr 24 '25 00:04 mohammed777200

https://github.com/dearimgui/dear_bindings

cfillion avatar Apr 24 '25 00:04 cfillion

https://github.com/dearimgui/dear_bindings

the problem is the "API" word, I wanna use it as a static library within my C code, such that the compiled program has zero latency of doing tons of API calls, you feel me bro!! thankssss

mohammed777200 avatar Apr 24 '25 02:04 mohammed777200

"API" does not imply a shared library. In fact, building dear imgui statically is the recommended usage.

  1. Grab dcimgui.{cpp,h} from the above repository's CI build page or generate them locally
  2. Build dear imgui and dcimgui.cpp (the glue code implementing dcimgui.h's C API to imgui.h's C++ API wrappers) as a static library (or even directly in the project if setup to build both C and C++)
  3. Include dcimgui.h and use its C API from your C code

cfillion avatar Apr 24 '25 02:04 cfillion

"API" does not imply a shared library. In fact, building dear imgui statically is the recommended usage.

  1. Grab dcimgui.{cpp,h} from the above repository's CI build page or generate them locally
  2. Build dear imgui and dcimgui.cpp (the glue code implementing dcimgui.h's C API to imgui.h's C++ API wrappers) as a static library (or even directly in the project if setup to build both C and C++)
  3. Include dcimgui.h and use its C API from your C code

Love it, thanks! But the issue is, I've compiled dcimgui.cpp into libdcimgui.a and link it with my project and use some of functions such as ImGui_GetVersion(), it yields this error in linker: demo.c:35|| undefined reference to `ImGui_GetVersion' || collect2: error: ld returned 1 exit status

I don't know why compiler can't link the library statically!!!

LDFLAGS= -I./lib -L./lib -ldcimgui -lcjson -lcurl -lm -lncurses -lglfw -lGL -ldl -lpthread
-lglut -ldbus-1
where ./lib is the directory supposed to contains libraries in src project dir!!

mohammed777200 avatar Apr 24 '25 03:04 mohammed777200

The error suggests that the libdcimgui found by the compiler doesn't actually contain dcimgui.o for some reason. (Also don't forget to compile dear imgui too: all 5 source files plus dcimgui.cpp into libdcimgui.a).

$ gcc -c dcimgui.cpp imgui{,_{widgets,tables,draw,demo}}.cpp
$ ar rcs libdcimgui.a *.o
$ cat test.c
#include <stdio.h>

#include "dcimgui.h"

int main() {
  printf("%s\n", ImGui_GetVersion());
}
$ gcc test.c -L. -ldcimgui -lm -lstdc++
$ ./a.out
1.92.0 WIP

cfillion avatar Apr 24 '25 10:04 cfillion

The error suggests that the libdcimgui found by the compiler doesn't actually contain dcimgui.o for some reason. (Also don't forget to compile dear imgui too: all 5 source files plus dcimgui.cpp into libdcimgui.a).

$ gcc -c dcimgui.cpp imgui{,_{widgets,tables,draw,demo}}.cpp $ ar rcs libdcimgui.a *.o $ cat test.c #include <stdio.h>

#include "dcimgui.h"

int main() { printf("%s\n", ImGui_GetVersion()); } $ gcc test.c -L. -ldcimgui -lm -lstdc++ $ ./a.out 1.92.0 WIP

It did worked when I compile project with outputted *.o object files, but not as static library even with your amazing way. But, did dcimgui cover all orignal C++ dear imgui? And I'm worry about implot which is based on C++ imgui which they have cimplot version based on cimgui and not dcimgui, thank u!

mohammed777200 avatar Apr 24 '25 16:04 mohammed777200

https://github.com/cimgui/cimgui exists also.

sonoro1234 avatar May 06 '25 08:05 sonoro1234