go build只对main包有效,在当前目录编译生成一个可执行的二进制文件(依赖包生成的静态库文件放在$GOPATH/pkg)。
go install一般生成静态库文件放在$GOPATH/pkg目录下,文件扩展名a,如果为main包,则会在$GOPATH/bin 生成一个可执行的二进制文件。
go build
通过go build加上要编译的Go源文件名,我们即可得到一个可执行文件,默认情况下这个文件的名字为源文件名字去掉.go后缀。
$ go build hello.go
$ lshello hello.go
当然我们也 可以通过-o选项来指定其他名字:
$ go build -o mygo hello.go
$ lsmygo hello.go
如果我们在go-examples目录下直接执行go build命令,后面不带文件名,我们将得到一个与目录名同名的可执行文件:
$ go build
$ lsgo-examples hello.go
go install
与build命令相比,install命令在编译源码后还会将可执行文件或库文件安装到约定的目录下。
1、go install编译出的可执行文件以其所在目录名(DIR)命名
2、go install将可执行文件安装到与src同级别的bin目录下,bin目录由go install自动创建
3、go install将可执行文件依赖的各种package编译后,放在与src同级别的pkg目录下
区别是:
go build去建造的意思。
go install去安装的决思。
例句辨析:
go build
1、They are going go build a new park next year.
明年他们将建一个新公园。
2、Go build things that help you in life& whether interacting with friends, family andorco-workers.
要和朋友、家人或是同事多多交流互动,培养对工作和生活有益的技能。
3、The library is too old. They're going go build a new one.
这个图书管太旧,他们打算建一个新的。
4、Rather than engaging the client to understand the problembeing tackled, we simply "do as we're told," and go build the system.
相对于为客户解决理解被处理的问题,我们简单地“做那些告诉我们的事情”,去构建系统。
go install
1、At this point, please go ahead and install WEKA.
我们继续并安装WEKA。
2、Now that you have created the ear file you can go ahead and install the enterprise application on Application server.
既然您已经创建了ear文件,就可以进一步在应用程序服务器上安装企业应用程序。
3、Now that all of the necessary files have been downloaded, let's go ahead and install them.
所有需要的文件都已下载,接下来安装它们。