Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with bindings for imgui library #46

Open
Xzya opened this issue Feb 15, 2018 · 6 comments
Open

Help with bindings for imgui library #46

Xzya opened this issue Feb 15, 2018 · 6 comments

Comments

@Xzya
Copy link

Xzya commented Feb 15, 2018

Hello,

I am trying to write bindings for imgui (cimgui) but I run in all kinds of problems, and I'm not sure what I'm doing wrong.

Here is my code, and I also have this test project with the minimal code to reproduce the problem.

Current I am getting the following errors:

# github.com/Xzya/go-imgui/imgui
cgo-gcc-prolog:47:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:60:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:61:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:62:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:63:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:94:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:111:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:156:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:157:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:158:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:159:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:175:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:176:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:177:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:178:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:179:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:180:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:181:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
cgo-gcc-prolog:182:17: error: field has incomplete type 'struct ImVec2'
imgui/cimgui/cimgui/cimgui.h:31:8: note: forward declaration of 'struct ImVec2'
fatal error: too many errors emitted, stopping now [-ferror-limit=]

and

# github.com/Xzya/go-bindings-test/imgui
imgui/cgo_helpers.go:121: ref74e98a33.x undefined (type *C.struct_ImVec2 has no field or method x)
imgui/cgo_helpers.go:125: ref74e98a33.y undefined (type *C.struct_ImVec2 has no field or method y)
imgui/cgo_helpers.go:149: x.ref74e98a33.x undefined (type *C.struct_ImVec2 has no field or method x)
imgui/cgo_helpers.go:150: x.ref74e98a33.y undefined (type *C.struct_ImVec2 has no field or method y)

I am not very familiar with C/C++, so there may be something very obvious that I am doing wrong.

Could you provide some help please?

Thank you!

@oakad
Copy link

oakad commented Feb 21, 2018

At least one of your files should have CIMGUI_DEFINE_ENUMS_AND_STRUCTS define set.

@Xzya
Copy link
Author

Xzya commented Feb 21, 2018

Hello,

I already tried this. Using #define CIMGUI_DEFINE_ENUMS_AND_STRUCTS 1 results in the following error:

# github.com/Xzya/go-imgui/imgui
In file included from imgui/cgo_helpers.go:9:
In file included from ./cgo_helpers.h:4:
./cimgui/cimgui/cimgui.h:84:8: error: redefinition of 'ImVec2'
struct ImVec2
       ^
./cimgui/cimgui/cimgui.h:84:8: note: previous definition is here
struct ImVec2
       ^
In file included from imgui/cgo_helpers.go:9:
In file included from ./cgo_helpers.h:4:
./cimgui/cimgui/cimgui.h:89:8: error: redefinition of 'ImVec4'
struct ImVec4
       ^
./cimgui/cimgui/cimgui.h:89:8: note: previous definition is here
struct ImVec4
       ^
In file included from imgui/cgo_helpers.go:9:
In file included from ./cgo_helpers.h:4:
./cimgui/cimgui/cimgui.h:96:5: error: redefinition of enumerator 'ImGuiWindowFlags_NoTitleBar'
    ImGuiWindowFlags_NoTitleBar = 1 << 0,
    ^
./cimgui/cimgui/cimgui.h:96:5: note: previous definition is here
    ImGuiWindowFlags_NoTitleBar = 1 << 0,
    ^
In file included from imgui/cgo_helpers.go:9:
In file included from ./cgo_helpers.h:4:
./cimgui/cimgui/cimgui.h:97:5: error: redefinition of enumerator 'ImGuiWindowFlags_NoResize'
    ImGuiWindowFlags_NoResize = 1 << 1,
    ^
...
many errors following the same pattern
...

I thought this was caused because the header was imported multiple times, so I tried adding #pragma once in the cimgui.h header, and the error changes to:

# github.com/Xzya/go-imgui/imgui
cgo-gcc-prolog:7306:41: warning: incompatible pointer types passing 'struct __va_list_tag *' to parameter of type 'struct __va_list_tag *' [-Wincompatible-pointer-types]
imgui/cimgui/cimgui/cimgui.h:781:102: note: passing argument to parameter 'args' here
cgo-gcc-prolog:7328:44: warning: incompatible pointer types passing 'struct __va_list_tag *' to parameter of type 'struct __va_list_tag *' [-Wincompatible-pointer-types]
imgui/cimgui/cimgui/cimgui.h:782:105: note: passing argument to parameter 'args' here
# github.com/Xzya/go-imgui/imgui
Undefined symbols for architecture x86_64:
  "_ImDrawData_DeIndexAllBuffers", referenced from:
      __cgo_3ccdb0436fb9_Cfunc_ImDrawData_DeIndexAllBuffers in imgui.cgo2.o
     (maybe you meant: __cgo_3ccdb0436fb9_Cfunc_ImDrawData_DeIndexAllBuffers)
  "_ImDrawData_ScaleClipRects", referenced from:
      __cgo_3ccdb0436fb9_Cfunc_ImDrawData_ScaleClipRects in imgui.cgo2.o
     (maybe you meant: __cgo_3ccdb0436fb9_Cfunc_ImDrawData_ScaleClipRects)
  "_ImDrawList_AddBezierCurve", referenced from:
      __cgo_3ccdb0436fb9_Cfunc_ImDrawList_AddBezierCurve in imgui.cgo2.o
     (maybe you meant: __cgo_3ccdb0436fb9_Cfunc_ImDrawList_AddBezierCurve)
  "_ImDrawList_AddCallback", referenced from:
      __cgo_3ccdb0436fb9_Cfunc_ImDrawList_AddCallback in imgui.cgo2.o
     (maybe you meant: __cgo_3ccdb0436fb9_Cfunc_ImDrawList_AddCallback)
  "_ImDrawList_AddCircle", referenced from:
      __cgo_3ccdb0436fb9_Cfunc_ImDrawList_AddCircle in imgui.cgo2.o
     (maybe you meant: __cgo_3ccdb0436fb9_Cfunc_ImDrawList_AddCircleFilled, __cgo_3ccdb0436fb9_Cfunc_ImDrawList_AddCircle )
  "_ImDrawList_AddCircleFilled", referenced from:
      __cgo_3ccdb0436fb9_Cfunc_ImDrawList_AddCircleFilled in imgui.cgo2.o
     (maybe you meant: __cgo_3ccdb0436fb9_Cfunc_ImDrawList_AddCircleFilled)
  "_ImDrawList_AddConvexPolyFilled", referenced from:
      __cgo_3ccdb0436fb9_Cfunc_ImDrawList_AddConvexPolyFilled in imgui.cgo2.o
     (maybe you meant: __cgo_3ccdb0436fb9_Cfunc_ImDrawList_AddConvexPolyFilled)

...
many errors following the same pattern
...

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Compilation finished with exit code 2

My guess is that CIMGUI_DEFINE_ENUMS_AND_STRUCTS is only intended to be used when generating code. E.g. I am using it when generating the code with c-for-go because it doesn't see the type declarations from the C++ code (imgui.h).

Any ideas?
Thank you!

@xlab
Copy link
Owner

xlab commented Feb 21, 2018

Undefined symbols for architecture x86_64:

Linking flags are missing, e.g. #cgo LDFLAGS or .c sources that contain those symbols.

@yaswagner
Copy link

Hi, I was wondering if there was a demo to understand how to use the binding generator? Thanks!

@sonoro1234
Copy link

https://github.com/cimgui/cimgui#generate-binding

@xlab
Copy link
Owner

xlab commented Oct 22, 2018

@yaswagner instead of writing a generator that consumes cimgui's JSON (as @sonoro1234 suggests, right?), I'd use c-for-go with a generated cimgui.h.

There is a plenty examples in the repo, see Nuklear and Vulkan bindings, both are made for a single-file API header.

@yaswagner regarding to errors above, I fixed c-for-go a couple of days ago, it should avoid duplicates. Please try again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants