自制go语言 go语言编译软件( 二 )


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",
直接调用"go build helloworld.go"就生成了"helloworld.exe"可执行程序,运行一下这个程序看到了我们期望的hello,wolrd 。
E:\opensource\go\go\testgo build helloworld.go
E:\opensource\go\go\testhelloworld.exe
hello, world
E:\opensource\go\go\test
附一 helloworld.go
// cmpout
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Test that we can do page 1 of the C book.
package main
func main() {
print("hello, world\n")
}
如何在win7环境下搭建Go开发环境首先需要下载下载go平台安装包
安装程序 下载地址址h如果是您的系统是windows32 位系统请选择go1.3.3.windows-386.msi即可,其他的,请按照自己所需版本来进行下载 , 如下图所示:
安装以及配置环境变量
由于Windows下的的安装包有两种:msi和zip的;zip的是免安装的 , 解压在配置一些环境变量之后就可以使用,msi的则是安装包版本的,安装的时候会设置好对应的环境变量 。我的电脑是Win7 64位 , 因为方便 , 就下载了下面的版本 。下好安装包后 , 安装过程就很简单了,一路“Next”就好了 。虽然msi会自动配置一些环境变量,但是本人在安装完之后还是自己配置了环境变量,所以在安装完Go之后,我们最好还是检查一些所有的环境变量是否正常 。主要的环境变量有以下几个:
GOROOT:Go的安装目录
GOPATH:用于存放Go语言Package的目录,这个目录不能在Go的安装目录中
GOBIN:Go二进制文件存放目录,写成%GOROOT%\bin就好
GOOS:操作系统
GOARCH:指定系统环境 , i386表示x86,amd64表示x64
PATH:需要将%GOBIN%加在PATH变量的最后,方便在命令行下运行Go
如下图所示:
像我自己安装的,下载完成之后解压到任意目录(所有目录均不能使用中文):D:\Go;
然后是go环境变量的配置:
GOARCH:386(go安装版本)
GOBIN:D:\Go\bin(exe执行文件路径)
GOOS:windows(go运行的系统)
GOROOT:D:\Go(go的解压路径)
GOPATH:E:\go\data(go的工具包路径 , 随意指定,后面会用到)
然后在path环境变量中追加:;%GOBIN%
完成之后在cmd窗口输入:go version,如下图所示:
go语言是什么Go语言是一种开源的编程语言,被广泛应用于网络编程、云计算、分布式系统等领域 。
go语言的三位作者
Go语言的设计目标是成为一种语法简洁、执行效率高、并发性能强大的编程语言 。它由Google公司研发,于2009年首次发布,并于2012年成为了开源项目 。Go语言具有C语言的表达能力和Python的开发效率,同时还拥有自己独特的语法和特性,如协程、垃圾回收机制等 。因此,它被广泛应用于网络编程、云计算、分布式系统等领域,并且越来越受到开发者的青睐 。

推荐阅读