Giter Site home page Giter Site logo

Help with bindings for imgui library about c-for-go HOT 6 OPEN

xlab avatar xlab commented on July 17, 2024
Help with bindings for imgui library

from c-for-go.

Comments (6)

sonoro1234 avatar sonoro1234 commented on July 17, 2024 2

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

from c-for-go.

xlab avatar xlab commented on July 17, 2024 1

@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.

from c-for-go.

oakad avatar oakad commented on July 17, 2024

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

from c-for-go.

Xzya avatar Xzya commented on July 17, 2024

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!

from c-for-go.

xlab avatar xlab commented on July 17, 2024

Undefined symbols for architecture x86_64:

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

from c-for-go.

yaswagner avatar yaswagner commented on July 17, 2024

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

from c-for-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.