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

Example code does not work? #91

Open
arjunmenon opened this issue Jun 8, 2024 · 7 comments
Open

Example code does not work? #91

arjunmenon opened this issue Jun 8, 2024 · 7 comments

Comments

@arjunmenon
Copy link

Hey, i am getting this

> go build .
github.com/go-gl/gl/v3.2-core/gl
github.com/golang-ui/nuklear/nk
# github.com/golang-ui/nuklear/nk
cgo-dwarf-inference:1:17: error: expected '{' before ')' token

was checking the nk-example.

@sp-manuel-jurado
Copy link

sp-manuel-jurado commented Jul 16, 2024

The same happens to me.

Build example:

...
go: downloading github.com/getlantern/systray v1.2.2
go: downloading github.com/golang-ui/nuklear v0.0.0-20231115163627-2440a671efc5
...
go: downloading github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71
go: downloading github.com/go-gl/glfw v0.0.0-20240506104042-037f3cc74f2a
...
# github.com/getlantern/systray
# [pkg-config --cflags  -- ayatana-appindicator3-0.1]
...
# github.com/go-gl/glfw/v3.2/glfw
...
# github.com/golang-ui/nuklear/nk
cgo-dwarf-inference:1:17: error: expected '{' before ')' token
2024/07/16 15:18:55 Failed to cross compile package: exit status 1.

Import go example:

import (
	"github.com/go-gl/gl/v3.2-core/gl"
	"github.com/go-gl/glfw/v3.2/glfw"
	"github.com/golang-ui/nuklear/nk"
)

Notes:

@Jamesthe1
Copy link

Jamesthe1 commented Jul 21, 2024

Getting this exact error as well from my own code just by having the inclusion. My go.mod looks like:

module test/nktest

go 1.22.5

require (
	github.com/golang-ui/nuklear v0.0.0-20231115163627-2440a671efc5
	github.com/veandco/go-sdl2 v0.4.40
)

require (
	github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 // indirect
	github.com/go-gl/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect
	github.com/xlab/android-go v0.0.0-20221106204035-3cc54d5032fa // indirect
)

and my import looks like:

import (
	"log"
	"os"
	"regexp"
	"runtime"
	"strconv"
	"strings"

	"github.com/golang-ui/nuklear/nk"
	"github.com/veandco/go-sdl2/sdl"
)

Even go install github.com/golang-ui/nuklear/nk simply triggers this error without it being present in imports.

Tried indirects as well, same result.

@anibaldeboni
Copy link

SDL2 example doesn't work either. It seems like the functions are based on some older nuklear api version, the arguments provided in the examples doesn't match the current api.

@hajimehoshi
Copy link

hajimehoshi commented Nov 4, 2024

Probably I see the same error.

% go mod init github.com/golang-ui/nuklear
% go mod tidy
% go build ./nk
# github.com/go-gl/glfw/v3.2/glfw
In file included from ../../go/pkg/mod/github.com/go-gl/[email protected]/v3.2/glfw/c_glfw_darwin.go:8:
../../go/pkg/mod/github.com/go-gl/[email protected]/v3.2/glfw/glfw/src/cocoa_window.m:989:9: warning: multiple methods named 'center' found [-Wobjc-multiple-method-names]
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSCollectionViewCompositionalLayout.h:602:19: note: using
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSWindow.h:417:1: note: also found
# github.com/golang-ui/nuklear/nk
cgo-dwarf-inference:1:17: error: expected identifier or '{'
__typeof__(enum ) *__cgo__0;
                ^
cgo-dwarf-inference:1:28: error: expected ')'
__typeof__(enum ) *__cgo__0;
                           ^
cgo-dwarf-inference:1:11: note: to match this '('
__typeof__(enum ) *__cgo__0;
          ^
2 errors generated.

My environment is like this:

% go version
go version go1.23.2 darwin/arm64
% fastfetch 
                     ..'          hajimehoshi@Hajimes-MacBook-Pro
                 ,xNMM.           -------------------------------
               .OMMMMo            OS: macOS 15.0.1 arm64
               lMM"               Host: MacBook Pro (14-inch, Nov 2023, Three Thunderbolt 4 ports)
     .;loddo:.  .olloddol;.       Kernel: 24.0.0
   cKMMMMMMMMMMNWMMMMMMMMMM0:     Uptime: 9 days, 14 hours, 12 mins
 .KMMMMMMMMMMMMMMMMMMMMMMMWd.     Packages: 148 (brew), 2 (brew-cask)
 XMMMMMMMMMMMMMMMMMMMMMMMX.       Shell: zsh 5.9
;MMMMMMMMMMMMMMMMMMMMMMMM:        Display (Color LCD): 3600x2338 @ 120Hz (as 1800x1169) [Built-in]
:MMMMMMMMMMMMMMMMMMMMMMMM:        DE: Aqua
.MMMMMMMMMMMMMMMMMMMMMMMMX.       WM: Quartz Compositor
 kMMMMMMMMMMMMMMMMMMMMMMMMWd.     WM Theme: Multicolor (Light)
 'XMMMMMMMMMMMMMMMMMMMMMMMMMMk    Font: .AppleSystemUIFont [System], Helvetica [User]
  'XMMMMMMMMMMMMMMMMMMMMMMMMK.    Cursor: Fill - Black, Outline - White (32px)
    kMMMMMMMMMMMMMMMMMMMMMMd      Terminal: tmux 3.3a
     ;KMMMMMMMWXXWMMMMMMMk.       CPU: Apple M3 Pro (12) @ 4.06 GHz
       "cooc*"    "*coo'"         GPU: Apple M3 Pro (18) [Integrated]
                                  Memory: 15.12 GiB / 18.00 GiB (84%)
                                  Swap: 15.35 GiB / 16.00 GiB (96%)
                                  Disk (/): 320.35 GiB / 926.35 GiB (35%) - apfs [Read-only]
                                  Local IP (en0): 192.168.0.10/24 *
                                  Battery: 80% [AC connected]
                                  Power Adapter: 96W USB-C Power Adapter
                                  Locale: C

@hajimehoshi
Copy link

I guess c-for-go failed to treat enums correctly:

// NkInputKey function as declared in nk/nuklear.h:837
func NkInputKey(arg0 *Context, arg1 C.enum_, down Bool) {
	carg0, carg0AllocMap := (*C.struct_nk_context)(unsafe.Pointer(arg0)), cgoAllocsUnknown
	carg1, carg1AllocMap := (C.enum_)(arg1), cgoAllocsUnknown
	cdown, cdownAllocMap := (C.nk_bool)(down), cgoAllocsUnknown
	C.nk_input_key(carg0, carg1, cdown)
	runtime.KeepAlive(cdownAllocMap)
	runtime.KeepAlive(carg1AllocMap)
	runtime.KeepAlive(carg0AllocMap)
}

@hajimehoshi
Copy link

xlab/c-for-go#174

@hajimehoshi
Copy link

hajimehoshi commented Nov 4, 2024

One of the necessary changes is

diff --git a/nk.yml b/nk.yml
index 237576e..bebea9b 100644
--- a/nk.yml
+++ b/nk.yml
@@ -70,6 +70,7 @@ TRANSLATOR:
       - {transform: export}
     const:
       - {action: accept, from: "(?i)^nk_"}
+      - {action: replace, from: "(?i)^nk_bool", to: "BoolType"}
       - {action: replace, from: "(?i)^nk_", to: _}
 
       - {action: ignore, from: _INT8}
       - 

Even with the PR xlab/c-for-go#176 and the above patch, I have not succeeded to compile this yet:

% go build ./nk
# github.com/golang-ui/nuklear/nk
nk/etc.go:26:26: cannot use content (variable of type string) as *byte value in argument to NkTexteditPaste
nk/impl_glfw_common.go:40:9: not enough return values
        have (string)
        want (string, error)
nk/impl_glfw_common.go:111:26: cannot use keyPressed(win, glfw.KeyDelete) (value of type int32) as Bool value in argument to NkInputKey
nk/impl_glfw_common.go:112:28: cannot use keyPressed(win, glfw.KeyEnter) (value of type int32) as Bool value in argument to NkInputKey
nk/impl_glfw_common.go:113:28: cannot use keyPressed(win, glfw.KeyKPEnter) (value of type int32) as Bool value in argument to NkInputKey
nk/impl_glfw_common.go:114:26: cannot use keyPressed(win, glfw.KeyTab) (value of type int32) as Bool value in argument to NkInputKey
nk/impl_glfw_common.go:115:32: cannot use keyPressed(win, glfw.KeyBackspace) (value of type int32) as Bool value in argument to NkInputKey
nk/impl_glfw_common.go:116:25: cannot use keyPressed(win, glfw.KeyUp) (value of type int32) as Bool value in argument to NkInputKey
nk/impl_glfw_common.go:117:27: cannot use keyPressed(win, glfw.KeyDown) (value of type int32) as Bool value in argument to NkInputKey
nk/impl_glfw_common.go:118:32: cannot use keyPressed(win, glfw.KeyHome) (value of type int32) as Bool value in argument to NkInputKey
nk/impl_glfw_common.go:118:32: too many errors

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