![]() You can check that the architecture of the generated binary is actually aarch64: $ GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=/usr/bin/aarch64-linux-gnu-gcc go build hello.go Then, you can cross-compile it like this: Here is a sample program that requires cgo, so that we can test the cross-compilation process: You need first to install the aarch64-linux-gnu-gcc cross-compiler. ![]() Say you want to cross-compile for $GOOS=linux and $GOARCH=arm64. On the other hand, if cgo is required for your build, you have to provide the path to your C/C++ cross-compilers, via the $CC/$CXX env vars. See the official documentation for the valid combinations of $GOOS and $GOARCH. If cgo is not required for your build, then simply specify the target OS and architecture as env vars to go build: The go command can natively cross-compile to a number of platforms. GOPATH=$HOME/go:$HOME/mygo Cross compiling to other platforms Tip: $GOPATH works like $PATH and can contain multiple entries, this can be useful to split out packages downloaded with go get and your own source code e.g. Go expects the source code to live inside $GOPATH, which is set to ~/go by default. You can check that Go is installed correctly by building a simple program, as follows:Ĭompilation with standard gc compiler (same as go build -compiler=gc hello.go):Ĭompilation with gccgo (same as go build -compiler=gccgo hello.go): This will provide various commonly used tools which will make working with Go easier, such as goimports, guru, gorename, etc. When in doubt: use go.Īn additional package that most Go developers will want to install is go-tools. In some cases gccgo may do better optimisations. ![]() The go command also include various tooling such as go get, go doc, etc.Īn alternative is gcc-go, which is a Go frontend for the GNU Compiler Collection (GCC). The standard Go compiler is go, which can be installed from the go package. Reason: Recommends go over gcc-go without stating why.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |