Go build based on Go command

an introduction

1. Used to compile source code files or code packages.
2. Compiling non-command source files will not produce any result files.
3. Compiling the command source file will generate an executable file in the execution directory of the command.
4. When executing this command without appending any parameters, it will try to compile the current directory as a code package.
5. When this command is executed with the import path of the code package as a parameter, the code package and its dependencies will be compiled.
After adding the -a flag, all involved code packages will be recompiled.
Without the -a flag, only the archive is not the latest code package to be compiled.
6. When this command is executed with several source files as parameters, only these files will be compiled.
 
Two actual combat
  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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326942155&siteId=291194637