e.g.
当前目录结构
- src
- hello
- Hello.go
- hello
go install
用 go install src/hello/Hello.go
编译 会出现以下错误
go install: no install location for .go files listed on command line (GOBIN not set)
这是因为对单个文件使用go install
,就会出现这个错误
应该用 go install hello
编译
就会编译出 bin/hello 文件
之后用 ./bin/hello
运行
go build
用 go build hello
会编译出 hello在当前目录下
此时 运行 hello
无法运行, 必须用 ./hello