Skip to content

Documentation around dear_bindings in a .dll / .so / .dylib for plugin-aware C software #107

@ludolpif

Description

@ludolpif

Hi,
I came more with questions than solutions initially, but I hope this can became a .md in this repository about how-to use dear_bindings in some non-trivial use cases.

To be transparent, I currently work on a mock up of a OBS like live streaming software, exploring alternative software designs here : https://ludolpif.fr/llss. I try a "plain C" mock up with this stack : SDL3 + SDL_gpu + (ImGui + dear_bindings for C) + FLECS + plugin-system based on SDL_loadso.h (which is dlopen() and for windows LoadLibrary()). Dynamically loaded plugins should be able to draw additional ImGui Window and widgets in the main app UI.
So I am particularly interested to get this use case nice and neat but document here other (hopefully simpler) use cases seems a positive thing to try to do, if they turn to have some dear_bindings specificity.

Various affirmations from original project :

  • "No specific build process is required" [1]
  • "It is recommended that you follow those steps and not attempt to build Dear ImGui as a static or shared library!" [2]
  • "Note that Dear ImGui is a very call-heavy API, so building as a shared library is not ideal because of increased function calling overhead" [2]
  • "If your application already uses the API you pulled the backends for, things should compile and link already." [2]
  • DLL users : [3]
    • Heaps and globals are not shared across DLL boundaries!
    • You will need to call SetCurrentContext() + SetAllocatorFunctions() for each static/DLL boundary you are calling from.
    • Same applies for hot-reloading mechanisms that are reliant on reloading DLL (note that many hot-reloading mechanisms work without DLL).
    • Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.

[1] https://github.com/ocornut/imgui?tab=readme-ov-file#usage
[2] https://github.com/ocornut/imgui/wiki/Getting-Started#compilinglinking
[3] https://github.com/ocornut/imgui/blob/v1.92.5/imgui.cpp#L1362

Note that I am trying to dig first the "dynamic loading" topic (which is dlopen() like) and not "dynamic linking" which is what the OS do when execve() a dynamically linked program) and in ImGui case is not recommended and except in a plugin-system based software, you could always skip it as far as I know.

I recently found "may be good" entry points around "dynamic loading"

Now : I am far from knowing everything is said there. But I hope learn. I am a linux sysadmin that know some of low-level stuff but not ELF details nor DLL model principles.

In the plugin-system based software case, few questions arose :

  • the "ABI" question : is a plugin compiled last year will be loadable in the newest release of the software ?
    • ImGui don't give any warranty, but the software may choose to upgrade ImGui only when it is raising ABI version for other reasons.
    • Plugin will use basic widgets, integrating frequently bleeding edge release of ImGui will probably never required.
  • the "where put the code" question :
    • ImGui + dear_binding code reside in the hosting software only ?
      • so it have to expose every dear_bindings C API functions as dynamic symbols to the plugins.
    • ImGui + dear_binding code reside in the plugins too ?
      • it may to greatly reduce dynamic symbol quantities (ImGui data structures only ?)
      • it may help to have near-maximal performance
      • but from a compiler to another (plugins authors aren't main software authors), bitfield layout or other problems could arise ?
  • the "how I really do compile" question :
    • in GNU/Linux and gcc toolchain world
    • in Windows Visual Studio world
    • (in MacOS X world but I didn't have any so I may never try myself)
  • the "don't try that" question :
    • what is already known to be a dead path to follow / explore ?

Hoping that some people have clues, ideas, think-out-the-box perspectives around here !
Thanks for all the fish,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions