diamondburned / gotk4

Autogenerated GTK4 bindings for Go
GNU Affero General Public License v3.0
492 stars 19 forks source link

Error Building For Windows #147

Open ququip123 opened 1 month ago

ququip123 commented 1 month ago

Compiling an app for windows amd64 gives me this error below, I tested this on both Linux (Fedora 40) & Windows 10 in a VM:

$ CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ GOOS=windows GOARCH=amd64 go build -o windows-amd64.exe cmd/main.go

# github.com/diamondburned/gotk4/pkg/core/gbox
In file included from _cgo_export.c:4:
cgo-gcc-export-header-prolog:49:35: error: conflicting types for 'callbackDelete'; have 'void(GoUintptr)' {aka 'void(long long unsigned int)'}
box.go:6:14: note: previous declaration of 'callbackDelete' with type 'void(guintptr)' {aka 'void(long unsigned int)'}
_cgo_export.c:26:28: error: conflicting types for 'callbackDelete'; have 'void(GoUintptr)' {aka 'void(long long unsigned int)'}
   26 | __declspec(dllexport) void callbackDelete(GoUintptr ptr)
      |                            ^~~~~~~~~~~~~~
box.go:6:14: note: previous declaration of 'callbackDelete' with type 'void(guintptr)' {aka 'void(long unsigned int)'}

here's a simple test app that has the same error:

package main

import (
    "log"
    "os"

    "github.com/diamondburned/gotk4/pkg/gdk/v4"
    "github.com/diamondburned/gotk4/pkg/gio/v2"
    "github.com/diamondburned/gotk4/pkg/gtk/v4"
)

func main() {
    app := gtk.NewApplication("com.test.asdf", gio.ApplicationFlagsNone)
    app.ConnectActivate(func() { activate(app) })

    if code := app.Run(os.Args); code > 0 {
        log.Println("error code: %d", code)
    }
}

func activate(app *gtk.Application) {
    window := gtk.NewApplicationWindow(app)
    window.SetDefaultSize(800, 500)

    gtk.StyleContextAddProviderForDisplay(
        gdk.DisplayGetDefault(),
        loadCSS(""),
        gtk.STYLE_PROVIDER_PRIORITY_APPLICATION,
    )

    child := gtk.NewLabel("test")

    window.SetChild(child)
    window.SetVisible(true)
}

func loadCSS(content string) *gtk.CSSProvider {
    prov := gtk.NewCSSProvider()
    // ...
    return prov
}
diamondburned commented 1 month ago

This is probably building for 32-bit C. Here, guintptr is defined as long unsigned int which is a 32-bit type.