dearimgui / dear_bindings

C header (and language binding metadata) generator for Dear ImGui
MIT License
221 stars 12 forks source link

Can I use this to use imgui from C using a C Compiler #62

Closed techie-guy closed 7 months ago

techie-guy commented 7 months ago

Basically the title.

I want to use imgui from C without messing with C++ and compile using a C compiler. Would that be possible?

ocornut commented 7 months ago

This library needs a C++ compiler to be built, but once built you can use it (aka include and link to it) using a C compiler.

techie-guy commented 7 months ago

Okay, Thanks!

techie-guy commented 7 months ago

When I run

python3 dear_bindings.py --backend -o cimgui_impl_opengl3 imgui/backends/imgui_impl_opengl3.h

to generate files for the backend, it tries to search the imgui/backends folder for imconfig.h and fails. Is there any way to fix this?

I have to copy the imconfig.h file to imgui/backends just to make it work!

The Full Output:

Dear Bindings: parse Dear ImGui headers, convert to C and output metadata.
Parsing /mnt/E278E1D278E1A58F/dev/projects/dear_bindings/imgui/backends/imconfig.h
Exception during conversion:
Traceback (most recent call last):
  File "/mnt/E278E1D278E1A58F/dev/projects/dear_bindings/dear_bindings.py", line 583, in <module>
    convert_header(
  File "/mnt/E278E1D278E1A58F/dev/projects/dear_bindings/dear_bindings.py", line 102, in convert_header
    dom_root.add_child(parse_single_header(include_file, context))
  File "/mnt/E278E1D278E1A58F/dev/projects/dear_bindings/dear_bindings.py", line 62, in parse_single_header
    with open(src_file, "r") as f:
FileNotFoundError: [Errno 2] No such file or directory: '/mnt/E278E1D278E1A58F/dev/projects/dear_bindings/imgui/backends/imconfig.h
ShironekoBen commented 7 months ago

Thanks for the report!

Yeah, the default behaviour is to assume that imconfig.h is in the same folder as the source file, which works fine for imgui.h but as you've discovered not so great if you are converting a backend that is in a different folder.

You can override the imconfig.h search directory by specifying --imconfig-path on the command line, which should fix it.

I'm kinda in two minds as to if there's another way to deal with this - on one hand, the current behaviour is definitely sub-optimal "out of the box" as backends are in their own folder in the default distribution. On the other, though, changing the default behavior from the simple and relatively obvious "imconfig.h is assumed to be in the same directory" to "imconfig.h is assumed to be in the same directory unless you specify --backend in which case it is assumed to be in the directory above" has the potential to be a much more confusing pitfall for anyone who is trying to use Dear Bindings in their own directory tree that doesn't match that setup.

I'll give this some more thought, but in the meantime hopefully --imconfig-path .. will work for you - give me a shout if you run into any other problems with this!

techie-guy commented 7 months ago

Okay, Thanks for the help!