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

building for windows from osx #19

Closed
ghost opened this issue Sep 28, 2018 · 5 comments
Closed

building for windows from osx #19

ghost opened this issue Sep 28, 2018 · 5 comments

Comments

@ghost
Copy link

ghost commented Sep 28, 2018

I cant get a Windows build :)

I have a setup for cross platform builds running from OSX and Linux.
But I cant build for Windows from OSX.

Would appreciate advice here !

Step to repo:


make build-win-fromosx

Makefile you can run from anywhere:



LIB=github.com/gen2brain/beeep
LIB_FSPATH=$(GOPATH)/src/$(LIB)

NAME=n

print:
	@echo Lib  -
	@echo LIB :$(LIB)
	@echo LIB_FSPATH  : $(LIB_FSPATH)
	#cd $(LIB_FSPATH) && ls -al 
	@echo


dep:
	go get $(LIB)

open-code:
	code $(LIB_FSPATH)

open-bash:
	bash $(LIB_FSPATH)


build-list:
	cd $(LIB_FSPATH) && ls -al

build-clean:
	cd $(LIB_FSPATH) && rm -rf $(NAME) go$(NAME) $(NAME).exe go$(NAME).exe *.tar.gz

build-win-fromosx:
	brew install mingw-w64

	go get gopkg.in/toast.v1

	#windows with cgo. It needs CGO
	#apt-get install gcc-multilib 
	#apt-get install gcc-mingw-w64
	cd $(LIB_FSPATH) && CC=i686-w64-mingw32-gcc-win32 CGO_ENABLED=1 GOOS=windows GOARCH=386 go build -o $(NAME).exe && tar zcfv "$(NAME)-windows-386.tar.gz" $(NAME).exe
	cd $(LIB_FSPATH) && rm -rf $(NAME).exe
	cd $(LIB_FSPATH) && CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -o $(NAME).exe && tar zcfv "$(NAME)-windows-amd64.tar.gz" $(NAME).exe
	cd $(LIB_FSPATH) && rm -rf $(NAME).exe

build-win-fromlinux:
	#windows with cgo
	#apt-get install gcc-multilib 
	#apt-get install gcc-mingw-w64
	cd $(LIB_FSPATH) && CC=i686-w64-mingw32-gcc-win32 CGO_ENABLED=1 GOOS=windows GOARCH=386 go build -o $(NAME).exe && tar zcfv "$(NAME)-windows-386.tar.gz" $(NAME).exe
	cd $(LIB_FSPATH) && rm -rf $(NAME).exe
	cd $(LIB_FSPATH) && CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -o $(NAME).exe && tar zcfv "$(NAME)-windows-amd64.tar.gz" $(NAME).exe
	cd $(LIB_FSPATH) && rm -rf $(NAME).exe


build-linux:
	#linux 
	go get github.com/godbus/dbus
	
	cd $(LIB_FSPATH) && CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o $(NAME) -ldflags "-s -w" && tar zcfv "$(NAME)-linux-386.tar.gz" $(NAME)
	cd $(LIB_FSPATH) && rm -rf $(NAME)
	cd $(LIB_FSPATH) && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(NAME) -ldflags "-s -w" && tar zcfv "$(NAME)-linux-amd64.tar.gz" $(NAME)
	cd $(LIB_FSPATH) && rm -rf $(NAME)

build-darwin:
	#darwin
	cd $(LIB_FSPATH) && CGO_ENABLED=0 GOOS=darwin GOARCH=386 go build -o $(NAME) -ldflags "-s -w" && tar zcfv "$(NAME)-darwin-386.tar.gz" $(NAME)
	cd $(LIB_FSPATH) && rm -rf $(NAME)
	cd $(LIB_FSPATH) && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o $(NAME) -ldflags "-s -w" && tar zcfv "$(NAME)-darwin-amd64.tar.gz" $(NAME)
	cd $(LIB_FSPATH) && rm -rf $(NAME)

	

@ghost ghost changed the title building for windows building for windows from osx Sep 28, 2018
@gen2brain
Copy link
Owner

Why do you want to build with CGO_ENABLED just on Windows? You need mingw toolchain if you are cross compiling something that use CGo, for native Go you don't need that.

@ghost
Copy link
Author

ghost commented Sep 28, 2018 via email

@gen2brain
Copy link
Owner

Nope, it builds template file and executes it with powershell. No cgo.

@gen2brain
Copy link
Owner

Actually for Windows in most cases you don't need to use cgo, e.g. https://github.com/gen2brain/dlgs/blob/master/dlgs_windows.go , better than Linux. For win32 API everything can be done with syscall, I guess only for new apis you will need cgo.

@ghost
Copy link
Author

ghost commented Sep 28, 2018

Pat king of you to help me learn.

Will close ..

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

1 participant