Skip to content

Error cross-compiling for windows/386 using xgo #143

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

Closed
jonbretman opened this issue Jul 13, 2018 · 11 comments
Closed

Error cross-compiling for windows/386 using xgo #143

jonbretman opened this issue Jul 13, 2018 · 11 comments
Labels
Milestone

Comments

@jonbretman
Copy link

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

@vcaesar
Copy link
Member

vcaesar commented Jul 16, 2018

I will test this tool when I have time.

@vcaesar vcaesar added this to the v0.50.0 milestone Jul 16, 2018
@jonbretman
Copy link
Author

@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.

@vcaesar
Copy link
Member

vcaesar commented Jul 29, 2018

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

@vcaesar vcaesar modified the milestones: v0.50.0, v0.60.0 Aug 8, 2018
@virtuald
Copy link

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

iwex commented Sep 6, 2018

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

@iwex
Copy link

iwex commented Sep 6, 2018

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){
                               ^

@vcaesar
Copy link
Member

vcaesar commented Sep 6, 2018

I will test it on Ubuntu 14.04.

@vcaesar vcaesar modified the milestones: v0.60.0, v0.70.0 Oct 9, 2018
@vcaesar vcaesar modified the milestones: v0.70.0, v0.80.0 Jan 7, 2019
@kongfei605
Copy link

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.

@kongfei605
Copy link

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.

@vcaesar
Copy link
Member

vcaesar commented Apr 1, 2019

Please check your environment configuration.

@xen0bit
Copy link

xen0bit commented Jun 5, 2020

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 ./

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants