Home  >  Article  >  Backend Development  >  Can golang be cross-platform?

Can golang be cross-platform?

(*-*)浩
(*-*)浩Original
2019-12-27 10:28:567043browse

Can golang be cross-platform?

#Golang supports cross-compilation, which means that if you develop on a 32-bit platform machine, you can compile and generate an executable program on a 64-bit platform.

# Cross -compilation Dependence The following environment variables: (Recommended Learning: Go )

## $ Goarch target platform (compiled after compilation The processor architecture (386, amd64, arm) of the target platform)

$GOOS The operating system (darwin, freebsd, linux, windows) of the target platform (compiled target platform)

Each Platform GOOS and GOARCH reference

OS                   ARCH                          OS version
linux                386 / amd64 / arm             >= Linux 2.6
darwin               386 / amd64                   OS X (Snow Leopard + Lion)
freebsd              386 / amd64                   >= FreeBSD 7
windows              386 / amd64                   >= Windows 2000

This method is useful for one-time compilation, testing, and learning, but it will cause some trouble when compiling multiple platforms at one time

First of all, you need to run the corresponding make.bash on the compiler for each platform you want to deploy to generate the required compiler.

You must execute the corresponding compilation command every time (this is a bit far-fetched, Because batch processing can also be achieved through the shell)

This machine needs to retain all generated compilers. If others also need such an environment, they need to perform the generation of the required compilers again

In order to keep this machine clean (hehe)

The above is the detailed content of Can golang be cross-platform?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn