go hello

1, the basic command:

    

go run .\hello\main.go

2, cross-platform compilation:

 

Cross-platform compiler 
default file we go build the executable file is the current operating system executable, if I want to compile a linux under the windows executable files that need to how to do it? 

Only you need to specify the target operating system platforms and processor architectures can be: 

the SET CGO_ENABLED = 0 // disable CGO 
the SET GOOS = // Linux target platform is Linux 
the SET GOARCH = amd64 // target processor architecture amd64 
then go build execution command to give is the ability to run on Linux platform executable files. 

Mac compile under Linux and Windows 64-bit executable programs: 

CGO_ENABLED GOOS = 0 = = GOARCH Linux AMD64 Go Build 
CGO_ENABLED GOOS = 0 = = AMD64 Windows GOARCH Go Build 
Linux compiler under Mac and Windows 64-bit executable programs: 

CGO_ENABLED = GOOS darwin GOARCH = = 0 AMD64 Go Build 
CGO_ENABLED GOOS = 0 = = AMD64 Windows GOARCH Go Build 
Windows 64-bit Mac platform compiler executable programs: 

the SET CGO_ENABLED = 0 
the SET GOOS = darwin 
the SET GOARCH = AMD64 
Go Build

  

  

Guess you like

Origin www.cnblogs.com/cbugs/p/12120693.html