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

is it possible to build win .exe's on linux? #50

Closed
mark-summerfield opened this issue Mar 14, 2023 · 5 comments
Closed

is it possible to build win .exe's on linux? #50

mark-summerfield opened this issue Mar 14, 2023 · 5 comments

Comments

@mark-summerfield
Copy link
Contributor

For command line applications I can usually build them on linux for windows using a command line like this:

But when I try this with a go-fltk app I get an error:

github.com/pwiecz/go-fltk: build constraints exclude all Go files in /home/mark/opt/gows/pkg/mod/github.com/pwiecz/[email protected]

It is possible, or must I build for windows on windows?

@pwiecz
Copy link
Owner

pwiecz commented Mar 14, 2023

I cannot read the command line.
Can you write it again?

@MoAlyousef
Copy link
Contributor

github.com/pwiecz/go-fltk: build constraints exclude all Go files in /home/mark/opt/gows/pkg/mod/github.com/pwiecz/[email protected]

It seems related to this issue:

golang/go#29074

@mark-summerfield
Copy link
Contributor Author

The command line was:

env GOOS=windows GOARCH=amd64 go build -o myapp.exe .

@MoAlyousef
Copy link
Contributor

I was able to get it working by specifying CGO_ENABLED=1 and specifying the cross-compiler, since according to the issue, the built-in C/C++ compiler in the golang toolchain isn't cross-compiling:

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

(uses the mingw cross-compiler)

I was also able to get things working using the Zig toolchain:

CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CXX="zig c++ -target x86_64-windows-gnu" CC="zig cc -target x86_64-windows-gnu" go build

@mark-summerfield
Copy link
Contributor Author

mark-summerfield commented Mar 15, 2023

I started by installing this: go install github.com/tc-hib/go-winres@latest. Then I installed the mingw cross-compiler. Then I changed my buildwin.sh script to:

go-winres simply --icon images/icon.ico
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc \
    CXX=x86_64-w64-mingw32-g++ \
    go build -buildvcs=false -ldflags -H=windowsgui -o myapp.exe .

Go insisted I add the -buildvcs=false flag and since I didn't want a console to pop up I added the -ldflags -H=windowsgui flag.

This created myapp.exe which won't run on win 7, but runs perfectly on win 10.

Note though that this depends on having mingw64 installed on windows and in the windows path: otherwise the .exe won't run because it can't find various dlls. So this approach does not produce a self-contained standalone .exe.

Thank you!

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

3 participants