Go命令基础之go build

来源:互联网 发布:excel一列数据求和 编辑:程序博客网 时间:2024/05/16 02:39

一 简介

1、用于编译源码文件或代码包。
2、编译非命令源码文件不会产生任何结果文件。
3、编译命令源码文件会在该命令的执行目录中生成一个可执行文件。
4、执行该命令且不追加任何参数时,它会试图把当前目录作为代码包并编译。
5、执行该命令且以代码包的导入路径作为参数时,该代码包及其依赖会被编译。
加入-a标记后,所有涉及到的代码包都会被重新编译。
不加入-a标记,则只会编译归档文件不是最新的代码包。
6、执行该命令且以若干源码文件作为参数时,只有这些文件会被编译。
 
二 实战
  1. [root@localhost ds]# ls
  2. showds.go
  3. [root@localhost ds]# go build showds.go
  4. [root@localhost ds]# ls
  5. showds showds.go
  6. [root@localhost ds]#./showds
  7. /root/goc2p/src/helper/ds:
  8. showds.go
  9. showds
  10. [root@localhost ds]# go run showds.go
  11. /root/goc2p/src/helper/ds:
  12. showds.go
  13. showds
  14. [root@localhost ds]# cd ../../pkgtool/
  15. [root@localhost pkgtool]# pwd
  16. /root/goc2p/src/pkgtool
  17. [root@localhost pkgtool]# go build
  18. [root@localhost pkgtool]# ls
  19. envir.go envir_test.go fpath.go ipath.go pnode.go util.go util_test.go