go-sdl2 icon indicating copy to clipboard operation
go-sdl2 copied to clipboard

[Help requested] Cross-compile from WSL to Windows

Open adam000 opened this issue 6 years ago • 6 comments

tl;dr: I'm trying to cross-compile an application using go-sdl2 and the Windows Subsystem for Linux (or WSL) to build a Windows binary on a Windows machine, without Windows hassles. There is a runtime error that I am trying to figure out:

Failed to load PNG: Failed loading libpng16-16.dll: The specified procedure could not be found.

The repository with a fully-reproducible build is here: https://github.com/adam000/go-sdl2-wsl-build-windows


The details:

Go version: go version go1.10.2 linux/amd64 (cross-compile to Windows) Using 64 bit mingw installed via apt-get

Operating system: Windows 10 version 1709 (OS Build 16299.431)

After seeing that v0.3 was launched and reading the README again, I noticed that there were some instructions for cross-compiling from Arch Linux to Windows, so I thought I'd give it a shot using the Windows Subsystem for Linux (which is built from Ubuntu Linux).

I installed Go with my homebuilt script: https://github.com/adam000/goutils/blob/master/scripts/make-go-latest.bash

Then, I installed some things via apt-get:

sudo apt-get install mingw-w64 unzip

So I tweaked the instructions from the README of go-sdl2 a bit and made a Go program and a bash script to make things easier on myself. The Go program handles the procurement and placement of all the necessary SDL libraries and development packages. The bash script wraps that and makes a cross-platform build, using the arguments described in the README of go-sdl2. It then copies it to the current user's Desktop on Windows.

I've created the repository using the texture_png example from the go-sdl2-examples repository, to eliminate any issues that may be specific to my private game's repository. I'm hoping that this repository will help in figuring out what my problem is. I find it very strange that it lists the error of being unable to use libpng16-16.dll when it shows up in my build:

image

Anyways, I know this is a lot but I'm hoping with these instructions, we can make it really easy to build go-sdl2 applications from WSL for Windows. I am very willing to contribute these scripts to the veandco team once we figure these issues out :)

adam000 avatar May 13 '18 16:05 adam000

Hi @adam000, I will give this a shot when I have a chance.

veeableful avatar May 15 '18 02:05 veeableful

Hi @adam000, I almost got this working on the Ubuntu WSL but failed at the last stage when cross compiling with the old SDL2/SDL2.h trap.

I have been trying to put a Windows 10 build together for some time.

I would love to see the results (no rush!)

Stuart

stuartdd avatar May 17 '18 22:05 stuartdd

I've installed WSL and tried the script yesterday and I've also come across the same issue being libpng16-16.dll not found. I'll try and see if I can't solve the problem.

veeableful avatar May 18 '18 01:05 veeableful

@veeableful @stuartdd Good and bad news! It seems that the project succeeds if I change the SDL_image version to 2.0.1 instead of the most current version, 2.0.3. (in my test project, this can be done by changing line 38 of build/grab-win64-resources-on-wsl.go)

The other bad news is that I won't have a Windows development machine for a week or so. I'm willing to ask around on the SDL forums when I get back.

adam000 avatar May 18 '18 21:05 adam000

An update: I was hoping to have better news and sooner, but I haven't heard anything back on the bug I submitted regarding this problem.

It appears to have been caused by SDL2_image updating its version of libpng. A workaround is providing the libpng dll from 2.0.1 with all of the other DLLs packaged with 2.0.3.

adam000 avatar Jul 16 '18 02:07 adam000

Hi, for SDL2_image to work properly, I copy the zlib1.dll file to current path of cmd. ~~Or copy all img.dll file to that.~~

eg:
Copy the zlib1.dll to %GOPATH%\src\github.com\veandco\go-sdl2\.go-sdl2-examples\examples\texture_png\

then

go run %GOPATH%\src\github.com\veandco\go-sdl2.go-sdl2-examples\examples\texture_png\texture_png.go

Suceru avatar Jan 26 '20 12:01 Suceru