go-vgo/robotgo

Error cross-compiling for windows/386 using xgo

jonbretman opened this issue · 11 comments

Not sure if this is a robotgo issue or an xgo issue but asking here just in case anyone can shine a light on what is going on.

Please see this xgo issue for info - karalabe/xgo#123

I will test this tool when I have time.

@vcaesar interestingly I ended up trying to build build my app on a Windows machine and got the same error:

In file included from ./bitmap/../base/str_io_c.h:2:0,
                 from ./bitmap/goBitmap.h:27,
                 from vendor/github.com/go-vgo/robotgo/robotgo.go:45:
./bitmap/../base/zlib_util_c.h:2:18: fatal error: zlib.h: No such file or directory

That was just go build and it's a 64 bit machine but when I tried to build with GOARCH=386 I got a different error, something about internalActive being undefined on this line https://github.com/go-vgo/robotgo/blob/master/robotgo_mac_win.go#L13.

If you just want to compile from windows to 32bit, please set cgo=1:

SET CGO_ENABLED=1
SET GOARCH=386
go build main.go

To get GOARCH=386 to compile from Ubuntu 16, I had to add the following to the top of zlib_util_c.h:

#if defined(IS_WINDOWS)
	#if defined (__x86_64__)
		#include "../cdeps/win64/zlib.h"
	#else
		#include "../cdeps/win32/zlib.h"
	#endif
#else
	#include <zlib.h>
#endif

Unfortunately, now there's a linker error where it can't find libz.

iwex commented

Same issue. Ubuntu 16.04. I have zlib1g-dev installed

iwex commented

I've tried @virtuald code and I got

/usr/bin/x86_64-w64-mingw32-ld: cannot find -lz
collect2: error: ld returned 1 exit status
# github.com/go-vgo/robotgo
../../go-vgo/robotgo/window/window.h: In function ‘get_title_by_hand’:
cc1: warning: function may return address of local variable [-Wreturn-local-addr]
In file included from ../../go-vgo/robotgo/window/goWindow.h:12:0,
                 from ../../go-vgo/robotgo/robotgo.go:49:
../../go-vgo/robotgo/window/window.h:604:31: note: declared here
 char* get_title_by_hand(MData m_data){
                               ^

I will test it on Ubuntu 14.04.

same proble with macos
os version:10.13.6 ,
golang version: 1.11.2.

add one line to resove problem "cannot find zlib.h"
38 #cgo windows CFLAGS: -I${SRCDIR}/cdeps/win64 // added to resove problem "cannot find zlib.h"
39 #cgo windows LDFLAGS: -lgdi32 -luser32
40 #cgo windows,amd64 LDFLAGS: -L${SRCDIR}/cdeps/win64 -lpng -lz

then ,it can't find libz. can anyone add libz.a to cdeps/win64 ?

i add two version of libz.a, but it does not work.

same proble with macos
os version:10.13.6 ,
golang version: 1.11.2.

add one line to resove problem "cannot find zlib.h"
38 #cgo windows CFLAGS: -I${SRCDIR}/cdeps/win64 // added to resove problem "cannot find zlib.h"
39 #cgo windows LDFLAGS: -lgdi32 -luser32
40 #cgo windows,amd64 LDFLAGS: -L${SRCDIR}/cdeps/win64 -lpng -lz

then ,it can't find libz. can anyone add libz.a to cdeps/win64 ?

i add two version of libz.a, but it does not work.

replace zlib.h zconf.h and add libz.a to cdeps/win64 with the same version, this problem sovled.

Please check your environment configuration.

For anyone looking to cross compile from Ubuntu 18.04 to Windows using Mingw64 and still getting the zlib.h error.

sudo apt install libz-mingw-w64-dev

GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build -x ./