2.1 Platforms and Architectures#
The Go language development team has developed compilers for the following operating systems:
- Linux
- FreeBSD
- Mac OS X (also known as Darwin)
Currently, there are two versions of the compiler: the native Go compiler gc and the non-native compiler gccgo. Both of these compilers work on Unix-like systems. The gc version of the compiler has been ported to the Windows platform and is integrated into major distributions. You can also use the gcc compiler on the Windows platform by installing MinGW. Both compilers work in a single-channel manner.
You can obtain the Go 1.4 source code and binary files for the following platforms:
- Linux 2.6+: amd64, 386, and arm architectures
- Mac OS X (Snow Leopard + Lion): amd64 and 386 architectures
- Windows 2000+: amd64 and 386 architectures
For low-level pure Go code or packages, portability across different operating systems is very strong. You only need to copy the source code to the corresponding platform for compilation, or you can use cross-compilation to build applications for the target platform. However, if you plan to use cgo or similar file monitoring systems, you will need to make appropriate modifications based on the actual situation.
-
Native Go compiler gc:
It is mainly based on the C toolchain used by Ken Thompson on the Plan 9 operating system.
The Go language compiler and linker are written in C and generate native code. Go does not have features like self-bootstrapping. Therefore, if you use a compiler with a different instruction set to build Go programs, you need to treat them differently based on the operating system and processor architecture (32-bit or 64-bit). (Note: Go has implemented self-bootstrapping since version 1.5. The Go language compiler and linker are written in Go.)
This compiler compiles in a non-generational, non-compressed, and parallel manner. It is faster than gccgo and produces better native code, but the compiled program cannot be linked using gcc.
The compiler currently supports program construction for the following Intel or AMD processor architectures.
Figure 2.1 Processor Architectures Supported by the gc Compiler
When you first see this naming system, you may find it strange, but these names are all from the Plan 9 project.
g = compiler: compiles source code into project code (program text)
l = linker: links project code to executable binary files (machine code)(The related C compiler names are 6c, 8c, and 5c, and the related assembler names are 6a, 8a, and 5a)
Flags refer to optional parameters that can be set via the command line to affect the build process of the compiler or linker or to obtain a special target result.
The available compiler flags are as follows:
flags:
-I directory search for packages in directory
-d print declaration information
-e do not limit the number of error prints
-f print stack structure
-h panic on error
-o specify output file name (see section 3.4)
-S print generated assembly code
-V print compiler version (see section 2.3)
-u disallow use of code in unsafe package
-w print syntax tree after type checking
-x print lex tokensStarting from Go version 1.0.3, instructions like
8g
and8l
are no longer used for program construction. Instead, unified commands likego build
andgo install
are used, and these commands automatically call the relevant compilers or linkers. -
gccgo compiler:
A more traditional compiler compared to gc, which uses GCC as the backend. GCC is a very popular GNU compiler that can build applications for many processor architectures. The compilation speed is relatively slower than gc, but the generated native code runs slightly faster. It also provides some interoperability with the C language.
Starting from Go version 1, both gc and gccgo have equivalent functionality in terms of compilation.
-
File extensions and packages:
The file extension for Go language source files is obviously
.go
.C files use the extension
.c
, and assembly files use the extension.s
. All source code files are organized into packages. Package files containing executable code are compressed and use the extension.a
(AR document).The standard library package files in Go language are installed in this format.
Note When creating directories, folder names should never contain spaces. Instead, use underscores "_" or other general symbols.