diamondburned / gotk4

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

Error compiling using mingw #131

Open Tom5521 opened 9 months ago

Tom5521 commented 9 months ago

Usually cgo usually compiles correctly with these environment variables

CC="clang -target x86_64-w64-mingw32-gcc"
CGO_ENABLED=1
GOOS=windows
GOARCH=amd64

But when I compile the program I get this

$ go build -v gtk4/simple/main.go
github.com/diamondburned/gotk4/pkg/core/gbox
# github.com/diamondburned/gotk4/pkg/core/intern
In file included from _cgo_export.c:4:
cgo-gcc-export-header-prolog:54:35: warning: redeclaration of 'goToggleNotify' should not add 'dllexport' attribute [-Wdll-attribute-on-redeclaration]
intern.go:7:14: note: previous declaration is here
# 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'
box.go:6:14: note: previous declaration is here
_cgo_export.c:26:28: error: conflicting types for 'callbackDelete'
box.go:6:14: note: previous declaration is here

I get almost the same error with gcc

First I thought it was something about missing mingw-gtk dependencies, but in a docker container with those dependencies I get the same error.

I get the same error as this issue but the difference is that I am on a 64 bit architecture.

SnoutBug commented 8 months ago

I was getting the same error, though I've had some success with

PKG_CONFIG_PATH=/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig
CGO_ENABLED=1
GOOS=windows
CC="x86_64-w64-mingw32-gcc"
go build -v -ldflags -H=windowsgui

taken from here but now I am getting the errors below:

main
# main
/usr/lib/golang/pkg/tool/linux_amd64/link: running x86_64-w64-mingw32-gcc failed: exit status 1
/usr/lib/gcc/x86_64-w64-mingw32/13.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -ladwaita-1: No such file or directory
/usr/lib/gcc/x86_64-w64-mingw32/13.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lgirepository-1.0: No such file or directory
/usr/lib/gcc/x86_64-w64-mingw32/13.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lgirepository-1.0: No such file or directory
/usr/lib/gcc/x86_64-w64-mingw32/13.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lgirepository-1.0: No such file or directory
collect2: error: ld returned 1 exit status
SnoutBug commented 8 months ago

After going on a hunt to find the required packages I found the needed files here. The mingw packages for libadwaita and and gobject-introspection do not seem to exist for Fedora.

After placing the package in the appropriate location I managed to compile my app.

As a small sidenote: bcryptprimitives.dll was missing when I tried to run the app with Wine. It appears, this dll is only included with Wine 9 and seems to be required see here.

Tom5521 commented 8 months ago

After going on a hunt to find the required packages I found the needed files here.

How did you install the corresponding packages?

I didn't have any problem with libadwaita after extracting the .tar.zst file in /usr/x86_64-w64-mingw32/

But with gobject-introspection it was not the case...

github.com/diamondburned/gotk4/pkg/core/gerror
# github.com/diamondburned/gotk4/pkg/core/gerror
# [pkg-config --cflags  -- glib-2.0 gobject-introspection-1.0]
Package gobject-introspection-1.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gobject-introspection-1.0.pc'
to the PKG_CONFIG_PATH environment variable
Package 'gobject-introspection-1.0', required by 'virtual:world', not found

So I decided to do this:

find /usr/x86_64-w64-mingw32/ -name "gobject-introspection-1.0.pc"
# /usr/x86_64-w64-mingw32/lib/pkgconfig/gobject-introspection-1.0.pc
ln /usr/x86_64-w64-mingw32/lib/pkgconfig/gobject-introspection-1.0.pc /usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig

But I get this error

github.com/diamondburned/gotk4/pkg/core/gerror
# github.com/diamondburned/gotk4/pkg/core/gerror
# [pkg-config --cflags  -- glib-2.0 gobject-introspection-1.0]
Package dependency requirement 'glib-2.0 >= 2.78.0' could not be satisfied.
Package 'glib-2.0' has version '2.77.1', required version is '>= 2.78.0'
Package dependency requirement 'gobject-2.0 >= 2.78.0' could not be satisfied.
Package 'gobject-2.0' has version '2.77.1', required version is '>= 2.78.0'

But I fixed it by modifying the file /usr/x86_64-w64-mingw32/lib/pkgconfig/gobject-introspection-1.0.pc

Changing these lines from this: Requires: glib-2.0 >= 2.78.0, gobject-2.0 >= 2.78.0 to this Requires: glib-2.0 >= 2.77.1, gobject-2.0 >= 2.77.1

I just want to know how safe it is to do that, or if the program will even work?

Or if I downloaded a wrong package that's why I had to do all the extra processing?

I leave this to leave more or less documented the process of how to get to this... in theory you just have to download and extract these 3 packages in /usr/x86_64-w64-mingw32/

And install these packages through dnf

Right now I already have a docker image to be able to automate it so... it would already be

diamondburned commented 8 months ago

Why not use MSYS2?

founderio commented 7 months ago

Why not use MSYS2?

MSYS2 compiles for Windows on Windows, mingw32 compiles for Windows on Linux. Running a separate machine/VM with windows, specially in a CI environment, is extra hassle which can be avoided by just cross-compiling.

diamondburned commented 7 months ago

Oh, interesting. That's a use case that I've never considered, unfortunately.