I am trying to cross compile Go for ubuntu linux x86_64 on my macbook. I have followed instructions outlined here but when I run go-linux-amd64 build
I get the following message go build runtime: linux/amd64 must be bootstrapped using make.bash
. Any help with this will be appreciated.
What it's saying you need to do is rebuild the library and runtime for linux-amd64. You can do that this way:
which go
may help - the binary is often installed with the rest of the sources).cd
into the src
directoryGOOS=linux GOARCH=amd64 ./make.bash --no-clean
(or GOOS=linux GOARCH=amd64 bash make.bash --no-clean
if make.bash
is not executable). This will rebuild the library and runtime using the specified OS and architecture.Once you've done this, you can build a go package or binary for this architecture using GOOS=linux GOARCH=amd64 go build
. You can follow the same instructions for other architectures and operating systems.
As of Go 1.5, cross compiling is much easier. Since the runtime is written in Go, there's no need to set anything up in order to be able to cross-compile. You can now just run GOOS=<os> GOARCH=<arch> go build
from a vanilla Go installation and it will work.
However, there's one exception to this. If you're using cgo, you'll still need to set stuff up ahead of time. And you'll need to inform the tooling that you want to enable cgo cross-compiling by setting the CGO_ENABLED
environment variable to 1
. So, to be precise:
cd
into the src
directory of your Go installation (see the instructions above).CGO_ENABLED=1 GOOS=<os> GOARCH=<arch> ./make.bash --no-clean
CGO_ENABLED=1 go build
to build your project. It is important that you specify CGO_ENABLED=1
even when you're compiling.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With