The story is: wrote an application on Go using PixelGl. Under Linux (and I work under ManjaroLinux) it compiles and runs fine. But when you try to do a go build for it under Windows64, the following happens:

[123@123 dir]$ export GOARCH=amd64 [123@123 dir]$ export GOOS=windows [123@123 dir]$ go build my_program_windows_amd64.go ../../go/git/src/github.com/faiface/glhf/frame.go:7:2: no buildable Go source files in /home/123/go/git/src/github.com/go-gl/gl/v3.3-core/gl ../../go/git/src/github.com/faiface/pixel/pixelgl/input.go:6:2: no buildable Go source files in /home/123/go/git/src/github.com/go-gl/glfw/v3.2/glfw

And compilation, of course, does not happen.

I understand that in order to compile this thing you need to build it under Windows

But how to do it - I can not understand. Do not manually collect them one by one, and under Linux they are automatically compiled when the project is compiled.

Therefore, please explain if anyone knows how to do cross-compilation

Just in case, I attach screenshots of $ GOROOT and $ GOPATH $ GOROOT

$ GOPATH


@ ainar-g tried to build a standard libu, did not work:

 [123@123 registry]$ go env GOARCH="amd64" GOBIN="" GOEXE=".exe" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="windows" GOPATH="/home/123/go/git" GORACE="" GOROOT="/usr/local/src/go" GOTOOLDIR="/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0" GCCGO="/usr/bin/gccgo" CC="x86_64-w64-mingw32-gcc" GOGCCFLAGS="-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build747939891=/tmp/go-build -gno-record-gcc-switches" CXX="x86_64-w64-mingw32-g++" CGO_ENABLED="1" PKG_CONFIG="pkg-config" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" [123@123 registry]$ go install std can't load package: /usr/local/src/go/src/bytes/bytes_amd64.go:7:8: non-standard import "internal/cpu" in standard package "bytes" can't load package: /usr/local/src/go/src/compress/flate/huffman_code.go:9:2: non-standard import "math/bits" in standard package "compress/flate" can't load package: /usr/local/src/go/src/crypto/sha1/sha1block_amd64.go:7:8: non-standard import "internal/cpu" in standard package "crypto/sha1" can't load package: /usr/local/src/go/src/crypto/sha256/sha256block_amd64.go:7:8: non-standard import "internal/cpu" in standard package "crypto/sha256" can't load package: /usr/local/src/go/src/crypto/sha512/sha512block_amd64.go:9:8: non-standard import "internal/cpu" in standard package "crypto/sha512" can't load package: /usr/local/src/go/src/crypto/tls/cipher_suites.go:18:2: non-standard import "golang_org/x/crypto/chacha20poly1305" in standard package "crypto/tls" can't load package: /usr/local/src/go/src/encoding/gob/decode.go:14:2: non-standard import "math/bits" in standard package "encoding/gob" can't load package: /usr/local/src/go/src/go/importer/importer.go:12:2: non-standard import "go/internal/srcimporter" in standard package "go/importer" can't load package: /usr/local/src/go/src/hash/crc32/crc32_amd64.go:12:2: non-standard import "internal/cpu" in standard package "hash/crc32" can't load package: /usr/local/src/go/src/math/floor_asm.go:9:8: non-standard import "internal/cpu" in standard package "math" can't load package: /usr/local/src/go/src/math/big/arith.go:11:8: non-standard import "math/bits" in standard package "math/big" can't load package: /usr/local/src/go/src/mime/type_windows.go:8:2: non-standard import "internal/syscall/windows/registry" in standard package "mime" can't load package: /usr/local/src/go/src/net/dial.go:10:2: non-standard import "internal/poll" in standard package "net" can't load package: /usr/local/src/go/src/net/http/h2_bundle.go:46:2: non-standard import "golang_org/x/net/http2/hpack" in standard package "net/http" can't load package: /usr/local/src/go/src/os/file.go:41:2: non-standard import "internal/poll" in standard package "os" can't load package: /usr/local/src/go/src/strings/strings_amd64.go:7:8: non-standard import "internal/cpu" in standard package "strings" can't load package: /usr/local/src/go/src/syscall/dll_windows.go:8:2: non-standard import "internal/syscall/windows/sysdll" in standard package "syscall" can't load package: /usr/local/src/go/src/time/zoneinfo_windows.go:9:2: non-standard import "internal/syscall/windows/registry" in standard package "time" 
  • Do you have a cross-compiler for Windows installed? - Ainar-G
  • @ Ainar-g what is this? I know only the usual, standard gcc - Bloody Altair
  • @ Ainar-G gccgo and gcc are - Bloody Altair
  • You need a C compiler that can produce code for Windows. Read, for example, here: rakyll.org/cross-compilation . - Ainar-G
  • @ ainar-g Delivered x86_64-mingw-w64, updated CC and CXX - Bloody Altair

2 answers 2

Solution found: stupidly we don’t install gccgo from the standard repository, we install gc, go-tools and the gcc package (do you don’t have it by default?), Download Go1.9 from the site, place it somewhere, prescribe variables in .bash -profile (be sure to specify the correct go in $ PATH binary)

Everything, we already have a working Go. But under Windows, it still does not collect. Okay

We put mingw-w64- (gcc + headers + crt + binutils).

Now everything is simple: in order to build under Windows / amd64 we create somewhere in $ PATH a file gowin64.sh with the following content:

 #!/bin/bash export CC=x86_64-w64-mingw32-gcc export CXX=x86_64-w64-mingw32-g++ export GOOS=windows export GOARCH=amd64 export CGO_ENABLED=1 go build -i -o ${1%.*}_${GOOS}_${GOARCH}.exe $1 

Everything, now we start and transfer to it as a parameter the name of the file * .go

     env GOOS=windows GOARCH=amd64 go build main.go 

    will compile main.exe under x64 bit windows system.

    rtfm rulezz.

    • it's not true, I told you - it doesn't work like this - Bloody Altair