英文:
go build behaves strangely
问题
我有以下的项目结构:
./
lib/ 共享库
cmd/
cli/
main.go
srv/
main.go
在main.go中,我有以下代码:
package main
import "fmt"
func main() {
fmt.Println("cli")
}
从根目录运行go build ./...,希望在根目录下创建cli和srv二进制文件,但什么都没有发生。
但是运行go build ./cmd/cli确实在根目录下产生了一个cli二进制文件。
有什么问题吗?
英文:
I have following project structure
./
lib/ shared library
cmd/
cli/
main.go
srv/
main.go
in the main.go i have
package main
import "fmt"
func main() {
fmt.Println("cli")
}
from root folder i run go build ./..., in a hope that cli and srv binaries would be created in a root folder, but nothing happens
but running go build ./cmd/cli does produce a cli binary in root folder
what is wrong?
答案1
得分: 1
从Go 1.13开始,如果你将-o标志明确设置为一个目录,go build命令将输出多个可执行文件。因此,例如,mkdir -p ./bin && go build -o ./bin ./...将构建与./...匹配的所有可执行文件,并将它们输出到目录./bin中。
英文:
As of Go 1.13, go build will output multiple executables if you set the -o flag explicitly to a directory. So, for example, mkdir -p ./bin && go build -o ./bin ./... will build all executables matching ./... and output them to the directory ./bin.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论