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

Error compiling using mingw #131

Open
Tom5521 opened this issue Feb 9, 2024 · 6 comments
Open

Error compiling using mingw #131

Tom5521 opened this issue Feb 9, 2024 · 6 comments

Comments

@Tom5521
Copy link

Tom5521 commented Feb 9, 2024

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.

@Tom5521 Tom5521 changed the title How to cross-compile from Linux to Windows? Error compiling using mingw Feb 11, 2024
@SnoutBug
Copy link

SnoutBug commented Mar 2, 2024

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
Copy link

SnoutBug commented Mar 3, 2024

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
Copy link
Author

Tom5521 commented Mar 4, 2024

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

  • mingw64-gtk4
  • mingw64-gcc
  • zstd (To extract the packages)

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

@diamondburned
Copy link
Owner

Why not use MSYS2?

@founderio
Copy link

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
Copy link
Owner

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

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

4 participants