Mac install and run go Helloword

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Haha, so excited, and come into contact with a powerful language, simply record the problem of running the first program on a Mac.

Hello Word Sample, pkg Install package: wget https://storage.googleapis.com/golang/go1.2.2.darwin-amd64-osx10.8.pkg, after downloading, need to set environment variable before OK Oh, like, my

Bash_profile file,

Goarch= "386" # 386 is from uname-p get the OH

Gobin= ""

Gochar= "6"

Goexe= ""

Gohostarch= "386" # 386 is from uname-p get the OH

Gohostos= "Darwin"

Goos= "Darwin"

Gopath= ""

Gorace= ""

goroot= "/usr/local/go"

Gotooldir= "/usr/local/go/pkg/tool/darwin_amd64"

term= "Dumb"

Cc= "Clang"

Gogccflags= "-g-o2-fpic-m64-pthread-fno-caret-diagnostics-qunused-arguments-fno-common"

cxx= "clang++"

cgo_enabled= "1"

source bash_profile can be;

If a similar error occurs at build (go build runtime:darwin/amd64 must be bootstrapped using Make.bash), you can try the following command to compile again:
$ Goos=darwin goarch=amd64 Go build-x-o testport_linux hello.go
work=/var/folders/vp/f5r3wgld1w133srlbyd4190m0000gn/t/go-build683397936
Mkdir-p $WORK/command-line-arguments/_obj/
Cd/users/jake/rdd/golang
/usr/local/go/pkg/tool/darwin_amd64/6g-o $WORK/command-line-arguments/_obj/_go_.6-p command-line-arguments- Complete-d _/users/jake/rdd/golang-i $WORK./hello.go
/usr/local/go/pkg/tool/darwin_amd64/pack GRCP $WORK $WORK/command-line-arguments.a $WORK/command-line-arguments/_ obj/_go_.6
Cd.
/usr/local/go/pkg/tool/darwin_amd64/6l-o testport_linux-l $WORK $WORK/COMMAND-LINE-ARGUMENTS.A
We found that go actually used the $GOROOT/PKG/TOOL/LINUX_AMD64 6g (compiler) and 6l (linker) to complete the entire compilation process, see 6g and 6l in the directory named Linux_amd64, we can boldly guess the compilation darwin/ The AMD64 go program should use the tools under $GOROOT/PKG/TOOL/DARWIN_AMD64. However, I did not find the DARWIN_AMD64 directory under the $goroot/pkg/tool, that is, we installed the installation package go only with the for LINUX_AMD64 compiler tool, to cross-compile the for DARWIN_AMD64 program, We need to compile these tools manually by Make.bash.
Based on Make.bash's usage instructions, let's try to build:


CD $GOROOT/SRC
sudo goos=darwin goarch=amd64./make.bash


After compiling, we'll try to compile the program for DARWIN_AMD64:


$ Goos=darwin goarch=amd64 Go build-x-o test_darwin hello.go


At this point, if the current directory generated the Test_darwin file, then execute, see the long-lost Hello world. Then modify the environment variables:
$ Export GOARCH=AMD64


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.