We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
go version
$ go version go version go1.15.6 linux/amd64
Yes.
go env
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/lenni/.cache/go-build" GOENV="/home/lenni/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/lenni/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/lenni/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/lib/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/lenni/git/easy-copy/go.mod" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build575804832=/tmp/go-build -gno-record-gcc-switches"
I created a small CGo Program which compiles on Windows:
// +build windows package main //#include <conio.h> //#include <stdio.h> import "C" import "fmt" func main() { ch := Getch() fmt.Printf("I got a %c\n", ch) } func Getch() rune { var ch int = int(C.getch()) return rune(ch) }
I am using Linux archlinux 5.9.14-arch1-1 #1 SMP PREEMPT Sat, 12 Dec 2020 14:37:12 +0000 x86_64 GNU/Linux. When I compile this using
Linux archlinux 5.9.14-arch1-1 #1 SMP PREEMPT Sat, 12 Dec 2020 14:37:12 +0000 x86_64 GNU/Linux
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=/usr/bin/x86_64-w64-mingw32-cc go build main.go
I get an executable that runs as expected (for reference, getch() reads a single keypress without having to press enter). If I replace the CC= with CC_FOR_windows_amd64, as mentioned in https://golang.org/cmd/cgo/#:~:text=When%20cross-compiling%2C%20you,run%20the%20go%20tool :
CC=
CC_FOR_windows_amd64
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC_FOR_windows_amd64=/usr/bin/x86_64-w64-mingw32-cc go build main.go
The build fails with
# runtime/cgo gcc: error: unrecognized command-line option ‘-mthreads’; did you mean ‘-pthread’?
So it looks like my linux gcc is called (which knows -pthread) instead of the mingw gcc (which knows -mthreads).
gcc
-pthread
-mthreads
Both commands work equally (the one with CC as well as the one with CC_FOR_windows_amd64 specified).
CC
go build with CC specified works as intended. go build with CC_FOR_windows_amd64 fails because it uses the wrong c compiler.
go build
The text was updated successfully, but these errors were encountered:
Also see #40616
Sorry, something went wrong.
I think you are misreading the docs (and maybe the docs are confusing). Setting CC_FOR_windows_amd64 only applies when running make.bash.
make.bash
What is make.bash and how do I use it? I found no docs on it so far.
make.bash is used when building a Go installation from source, as described at https://golang.org/doc/install/source.
When actually using Go, rather than building it from source, you need to set CC.
Oh ok, thank you very much.
No branches or pull requests
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I created a small CGo Program which compiles on Windows:
I am using
Linux archlinux 5.9.14-arch1-1 #1 SMP PREEMPT Sat, 12 Dec 2020 14:37:12 +0000 x86_64 GNU/Linux
.When I compile this using
I get an executable that runs as expected (for reference, getch() reads a single keypress without having to press enter).
If I replace the
CC=
withCC_FOR_windows_amd64
, as mentioned in https://golang.org/cmd/cgo/#:~:text=When%20cross-compiling%2C%20you,run%20the%20go%20tool :The build fails with
So it looks like my linux
gcc
is called (which knows-pthread
) instead of the mingwgcc
(which knows-mthreads
).What did you expect to see?
Both commands work equally (the one with
CC
as well as the one withCC_FOR_windows_amd64
specified).What did you see instead?
go build
withCC
specified works as intended.go build
withCC_FOR_windows_amd64
fails because it uses the wrong c compiler.The text was updated successfully, but these errors were encountered: