cimgui / cimnodes

C wrapping of https://github.com/Nelarius/imnodes
28 stars 15 forks source link

namespacing issues? #2

Closed benmkw closed 3 years ago

benmkw commented 3 years ago

I'm having the following issues when trying to wrap this api https://github.com/benmkw/imnodes-rs#todo where I'm not yet sure if its my fault (may very well be). Could you tell me if it works for you so that I can be sure its an issue on my side? :D

ug/build/imnodes-sys-655e2915e490d9bd/out/third-party/cimnodes/cimnodes.o" "-c" "third-party/cimnodes/cimnodes.cpp"
  cargo:warning=third-party/cimnodes/cimnodes.cpp:44:12: error: cannot initialize return object of type 'EditorContext *' with an rvalue of type 'imnodes::EditorContext *'
  cargo:warning=    return imnodes::EditorContextCreate();
  cargo:warning=           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  cargo:warning=third-party/cimnodes/cimnodes.cpp:48:39: error: cannot initialize a parameter of type 'imnodes::EditorContext *' with an lvalue of type 'EditorContext *'
  cargo:warning=    return imnodes::EditorContextFree(noname1);
  cargo:warning=                                      ^~~~~~~
  cargo:warning=third-party/cimnodes/./imnodes/imnodes.h:148:38: note: passing argument to parameter here
  cargo:warning=void EditorContextFree(EditorContext*);
  cargo:warning=                                     ^
  cargo:warning=third-party/cimnodes/cimnodes.cpp:52:38: error: cannot initialize a parameter of type 'imnodes::EditorContext *' with an lvalue of type 'EditorContext *'

// etc ...
sonoro1234 commented 3 years ago

Yes, It works for me in https://github.com/sonoro1234/LuaJIT-ImGui.

I dont know how your wrapping works. Perhaps you could ask to others having rust bindings to cimgui modules. (look for them in https://github.com/cimgui/cimgui: https://github.com/Gekkio/imgui-rs or https://github.com/4bb4/implot-rs)

But from a C perspective you should not wrap cimnodes.cpp (then you could wrap imnodes.cpp directly). Instead you should compile cimnodes.cpp (probably with cimgui.cpp and some backend also) and then wrap the generated module (.dll or .so) with the definitions found in cimnodes.h when you define CIMGUI_DEFINE_ENUMS_AND_STRUCTS

But when you are building cimnodes.cpp you should not define CIMGUI_DEFINE_ENUMS_AND_STRUCTS and this is perhaps your error.

benmkw commented 3 years ago

Yes you are right, got it compiling, thanks!

(that's my first time wrapping something using rust, or actually wrapping at all so..)

juliusl commented 2 years ago

Sorry to reopen this.

I was wondering, why is the namespace defined as imnodes when generating cimnodes.cpp, when in imnodes, it's defined as ImNodes. If I change the namespace in imnodes.h to imnodes, everything compiles okay, otherwise it's a compiler error.

So I feel like I might be missing something simple.

sonoro1234 commented 2 years ago

as done in https://github.com/sonoro1234/LuaJIT-ImGui/blob/docking_inter/CMakeLists.txt this definition is necessary: add_definitions(-DIMNODES_NAMESPACE=imnodes) for compilation because it is also used in the generation. (dont change imnodes.h for this) The reason is to avoid colliding with the same namespace in https://github.com/rokups/ImNodes in case both are used at the same time. (as I do myself) This was raised for the first time in https://github.com/Nelarius/imnodes/issues/97