Translate cimgui code

I’m new to zig lang and “translate-c” functionality (of it).

I had tried translating raylib and it went without a problem :grinning:

Then I was taking care of cimgui with zig translate-c -I libs/cimgui -I libs/cimgui/generator/ -I libs/cimgui/imgui/ -l c++ libs/cimgui/cimgui.h, but I always get:

libs/cimgui/imgui/imgui.h:258:43: must use 'struct' tag to refer to type 'ImGuiInputTextCallbackData'
libs/cimgui/imgui/imgui.h:259:38: must use 'struct' tag to refer to type 'ImGuiSizeCallbackData'
libs/cimgui/imgui/imgui.h:269:5: unknown type name 'constexpr'
libs/cimgui/imgui/imgui.h:269:47: call to undeclared function 'x'; ISO C99 and later do not support implicit function declarations
libs/cimgui/imgui/imgui.h:269:58: expected parameter declarator
libs/cimgui/imgui/imgui.h:269:58: expected ')'
libs/cimgui/imgui/imgui.h:269:56: duplicate member 'y'
libs/cimgui/imgui/imgui.h:269:63: expected ';' at end of declaration list
libs/cimgui/imgui/imgui.h:282:5: unknown type name 'constexpr'
libs/cimgui/imgui/imgui.h:282:76: expected parameter declarator
libs/cimgui/imgui/imgui.h:282:76: expected ')'
libs/cimgui/imgui/imgui.h:282:74: duplicate member 'y'
libs/cimgui/imgui/imgui.h:282:85: expected parameter declarator
libs/cimgui/imgui/imgui.h:282:85: expected ')'
libs/cimgui/imgui/imgui.h:282:83: duplicate member 'z'
libs/cimgui/imgui/imgui.h:282:94: expected parameter declarator
libs/cimgui/imgui/imgui.h:282:94: expected ')'
libs/cimgui/imgui/imgui.h:282:92: duplicate member 'w'
libs/cimgui/imgui/imgui.h:282:99: expected ';' at end of declaration list
(no file):1:1: too many errors emitted, stopping now

I tried multiple things, but I always end up with similar errors :melting_face:

Zig Version - master / nightly

PS. I know that zig-imgui exists, but I want to know how generate it automatically.

From personal experience, Zig can translate some (maybe alot) of C, but definitely not everything. I.E. #13968

I am currently attempting to understand how the zig compiler works, but I think we will have to wait some time before Zig can fully translate C.

imgui is a C++ library. You definitely cannot translate C++ with translate-c.

Yee, but cimgui is c wrapper.

But somehow it got compiling imgui/imgui.h which is part of the C++ code-base.

You only need cimgui.h.

zig translate-c cimgui.h -DCIMGUI_DEFINE_ENUMS_AND_STRUCTS -lc

I have just managed to build my zig version of cimgui example program. Everything is compiled / linked with Zig - dear imgui, cimgui and the example (main.zig).
I don’t use zig translate-c, just compile .cpp files with zig and use @cImport for headers.

If you’re interested, I can post my experiments.

It’s C++ (except for cimgui.h, maybe, but that’s debatable).
Notice that cimgui.cpp is a cpp file. All the wrapper functions in it are declared as extern “C”, to be callable from C, but since they themselves have to call C++ functions, they have to be C++.