You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The help for go build doesn't correctly describe what the effect of -o has on the output file (if any). It also seems internally inconsistent.
From experimenting on the command line -o /tmp/foo will produce an object file when building non-main packages iff the package is somewhere in goroot or a gopath. Specifically running go build -o /tmp/foo at the directory:
$GOROOT/src/fmt – object file created
$GOPATH/src/golang.org/x/net/context – object file created
/tmp/my_binary (containing package main main.go) – binary file created
/tmp/my_pkg (contain package foo foo.go) – no file created
Further, the output of go help build seems to contradict itself. It first states that the results will be discarded for anything other than a single package main. The next paragraph then describes what the output file name will be for non-main packages if no other name is specified.
When the command line specifies a single main package,
build writes the resulting executable to output.
Otherwise build compiles the packages but discards the results,
serving only as a check that the packages can be built.
The -o flag specifies the output file name. If not specified, the
output file name depends on the arguments and derives from the name
of the package, such as p.a for package p, unless p is 'main'. If
the package is main and file names are provided, the file name
derives from the first file name mentioned, such as f1 for 'go build
f1.go f2.go'; with no files provided ('go build'), the output file
name is the base name of the containing directory.
The text was updated successfully, but these errors were encountered:
robpike
changed the title
go help build incorrectly describes behaviour of flag -o
cmd/go: go help build incorrectly describes behaviour of flag -o
Jun 1, 2015
The help for go build doesn't correctly describe what the effect of
-o
has on the output file (if any). It also seems internally inconsistent.From experimenting on the command line
-o /tmp/foo
will produce an object file when building non-main packages iff the package is somewhere in goroot or a gopath. Specifically runninggo build -o /tmp/foo
at the directory:package main
main.go) – binary file createdpackage foo
foo.go) – no file createdFurther, the output of
go help build
seems to contradict itself. It first states that the results will be discarded for anything other than a single package main. The next paragraph then describes what the output file name will be for non-main packages if no other name is specified.The text was updated successfully, but these errors were encountered: