Skip to content

Errors cross compile to windows 64 #303

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
tiaguinho opened this issue May 9, 2016 · 10 comments
Closed

Errors cross compile to windows 64 #303

tiaguinho opened this issue May 9, 2016 · 10 comments

Comments

@tiaguinho
Copy link

tiaguinho commented May 9, 2016

I'm trying cross compile from linux to windows 64 and the following error has occurred

runtime/cgo
gcc: error: unrecognized command line option ‘-mthreads’

Any ideias?

@tiaguinho tiaguinho changed the title Erros cross compile to windows 64 Errors cross compile to windows 64 May 9, 2016
@mattn
Copy link
Owner

mattn commented May 10, 2016

Are you using mingw64 C compiler on linux?

@tiaguinho
Copy link
Author

tiaguinho commented May 10, 2016

I wasn't.
But after some research I found a page in stackoverflow so i try.
First install this two packages

apt-get install gcc-multilib
apt-get install gcc-mingw-w64

After that I use this command to compile

GOOS=windows GOARCH=386 CGO_ENABLED=1 CXX_FOR_TARGET=i686-w64-mingw32-g++ CC_FOR_TARGET=i686-w64-mingw32-gcc go build

This works for me.

@x1unix
Copy link

x1unix commented Sep 16, 2020

@tiaguinho you can build your app in go-mingw Docker container which contains all necessary MinGW deps].

tryffel added a commit to tryffel/testrepo that referenced this issue Mar 28, 2021
* use docker image that has mingw-compiling configured
* for more, see mattn/go-sqlite3#303
@williambrode
Copy link

Anyone know how to fix this? @tiaguinho solution doesn't seem to work (I'm guessing that's why it has so many downvotes). Building in the go-mingw docker container works but is extremely slow. Would like to be able to build locally.

@x1unix
Copy link

x1unix commented Aug 24, 2021

@williambrode mount your GOPATH (or use Docker volume) to keep Go build cache.

See https://github.com/x1unix/docker-go-mingw#go-build-cache

@rittneje
Copy link
Collaborator

@williambrode Should be something like this:

sudo apt-get install gcc-mingw-w64
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build ...

Be sure to set CC, not CXX_FOR_TARGET/CC_FOR_TARGET. Those two are only relevant when building the Go compiler from scratch.

@mateors
Copy link

mateors commented Nov 23, 2021

@rittneje thank you very much, its worked for me, i am using linux ubuntu.

first installed the package then compiled for windows as follows.

sudo apt-get install gcc-mingw-w64
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build 

@elgs
Copy link

elgs commented Mar 12, 2023

@rittneje this works thanks! But it doesn't seem to work for GOARCH=arm64.

@navaneeth-dev
Copy link

Works on amd64. But can anyone tell me what is the difference between gcc-mingw-w64 and mingw-w64 package in debian

@x1unix
Copy link

x1unix commented Apr 30, 2023

@navaneeth-dev mingw-w64 is a metapackage that includes gcc-mingw-w64, which is a C compiler.

See https://packages.debian.org/buster/mingw-w64

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

8 participants