dearimgui / dear_bindings

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

Example of building a static library #66

Closed sampletext32 closed 4 months ago

sampletext32 commented 4 months ago

Hi, first thing I should say is thank you for this project.

I'm currently working on generating bindings for dotnet.

I'm not a C++ developer in any way, so I kinda worked my way through original cimgui trying to copy-paste some steps.

Here's a problem I have - after building the generated definitions, dll explorer gives me a ton of _Z* functions: image which differs from cimgui.dll build from cimgui repo, where dll explorer gives only functions ig* and nothing more: image

I suppose that I have compiled this repo in some weird manner, and that produced all that junk in the resulting dll.

Here is a .Dockerfile I use to compile this repo for windows and linux https://github.com/DearImGuiBindingsNet/DearImGuiBindingsNet/blob/master/dear_bindings.Dockerfile if you wish to try it out - use commands in the readme.

I'm seeking some help in using gcc to produce the best result (without junk).

Thanks everyone in advance.

ShironekoBen commented 4 months ago

Hmm... so the _Z* stuff looks like C++ name mangling at work, so I think you're exporting the C++ symbols from ImGui rather than the C ones. Looking at your dockerfile, it seems to be setting -DIMGUI_IMPL_API='extern "C" __declspec(dllexport)', which I suspect would have that effect as IMGUI_IMPL_API is the macro used by the original C++ headers, not the C ones, which use CIMGUI_IMPL_API.

So my first guess would be to try changing that to -DCIMGUI_IMPL_API='extern "C" __declspec(dllexport)' and see if that fixes things (as you're not exporting backend functions you might want to use CIMGUI_API instead, although in this situation I don't think it would actually matter).

sampletext32 commented 4 months ago

@ShironekoBen Thank you so much. I replaced (for linux) -DIMGUI_IMPL_API=extern"C" \ with -DCIMGUI_API='extern "C"' and (for windows) -DIMGUI_IMPL_API='extern "C" __declspec(dllexport)' with -DCIMGUI_API='extern "C" __declspec(dllexport)'

And now my dll looks like this image

sampletext32 commented 4 months ago

Btw, can my project be included in Software using Dear Bindings because now it actually compiles correctly and I've just managed to run a example_null sample in .NET8 image

ShironekoBen commented 4 months ago

Cool, glad to hear that worked! I've added an entry to the wiki page for your project. Just shout if there's anything else I might be able to help with!