go语言编译过程概述 go编译命令( 三 )


3.3 GOARM
表示使用的浮点运算协处理器版本号,只对arm平台有用,可选值有5,6,7 。如果是在目标平台上编译源代码,这个值可以不设置,它会自动判断需要使用哪一个版本 。
总结下来,在树莓派上设置golang的编译环境变量,可编辑$HOME/.bashrc文件,在末尾添加下面内容:
export GOROOT=你的go目录路径
export GOOS=linux
export GOARCH=arm
编辑完后保存,执行source ~/.bashrc命令让修改生效 。
4、编译源代码
环境变量配置完成自后就可以开始编译源代码 。在go目录下的src子目录中,主要有all.bash和make.bash两个脚本(另外还有两个all.bat和make.bat脚本适用于window平台) 。编译实际上就是执行其中一个脚本 , 两者的区别在于all.bash在编译完成后还会执行一些测试套件 。如果希望只编译不测试,可以运行make.bash脚本 。使用cd命令进入go下src目录,执行./all.bash或者./make.bash命令即可开始编译 。由于硬件情况不同,编译耗费的时间不同 。在我的B型树莓派编译过程花费了将近半个小时,编译完成后执行的测试套件又花费了差不多一个小时,总共花费了一个半小时左右 。
5、配置golang运行环境变量
编译完成后 , go目录下会生成bin目录,里面就是go的运行脚本 。为了以后使用方法,可以将这个bin路径添加到PATH环境变量中 。同样编辑~/.bashrc文件,因为前面设置过GOROOT环境变量指向go目录了,所以只需要在末尾加上
export PATH=$PATH:$GOROOT/bin
保存后同样执行source ~/.bashrc命令让环境变量生效 。
至此,golang源代码编译安装成功 。执行go version应该就能看到当前golang的版本信息 , 表示编译安装成功 。
windows 怎么编译 go语言1、解压压缩包到go工作目录go语言编译过程概述,如解压到E:\opensource\go\go , 解压后的目录结构如下go语言编译过程概述:
E:\opensource\go\go
├─api
├─bin
│├─go.exe
│├─godoc.exe
│└─gofmt.exe
├─doc
├─include
├─lib
├─misc
├─pkg
├─src
└─test
2、增加环境变量GOROOT,取值为上面的go工作目录
3、Path环境变量中添加";%GOROOT%\bin",以便能够直接调用go命令来编译go代码,至此go编译环境就配置好了
注:如果不想手动设置系统环境变量 , 也可下载go启动环境批处理附件,
修改goenv.bat文件中的GOROOT值为上面的go工作目录后直接双击该bat文件,go编译环境变量即设置完成 。
4、测试go编译环境,启动一个cmd窗口,直接输入go,看到下面的提示就是搭建成功了
E:\opensource\go\gogo
Go is a tool for managing Go source code.
Usage:
go command [arguments]
The commands are:
buildcompile packages and dependencies
cleanremove object files
docrun godoc on package sources
envprint Go environment information
fixrun go tool fix on packages
fmtrun gofmt on package sources
getdownload and install packages and dependencies
installcompile and install packages and dependencies
listlist packages
runcompile and run Go program
testtest packages
toolrun specified go tool
versionprint Go version
vetrun go tool vet on packages
Use "go help [command]" for more information about a command.
Additional help topics:
gopathGOPATH environment variable
packagesdescription of package lists
remoteremote import path syntax
testflagdescription of testing flags
testfuncdescription of testing functions
Use "go help [topic]" for more information about that topic.
5、编译helloworld测试程序,go语言包中test目录带有helloworld.go测试程序,源码见"附一 helloworld.go",

推荐阅读