Dear ImGui for pure C lang
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();
https://github.com/dearimgui/dear_bindings
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
"API" does not imply a shared library. In fact, building dear imgui statically is the recommended usage.
- Grab dcimgui.{cpp,h} from the above repository's CI build page or generate them locally
- 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++)
- Include dcimgui.h and use its C API from your C code
"API" does not imply a shared library. In fact, building dear imgui statically is the recommended usage.
- Grab dcimgui.{cpp,h} from the above repository's CI build page or generate them locally
- 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++)
- 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!!
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
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!
https://github.com/cimgui/cimgui exists also.