Thanks for the information.

Personally, I think the behavior is hard to predict. The binary should be 
only produced when a single path is specified.

On Monday, April 19, 2021 at 10:59:33 AM UTC-4 Brian Candler wrote:

> In short, yes this is as intended, although somewhat obscure.  The 
> documentation is here 
> <https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies>:
>
> *"When compiling a single main package, build writes the resulting 
> executable to an output file named after the first source file ('go build 
> ed.go rx.go' writes 'ed' or 'ed.exe') or the source code directory ('go 
> build unix/sam' writes 'sam' or 'sam.exe'). The '.exe' suffix is added when 
> writing a Windows executable.*
>
> *When compiling multiple packages or a single non-main package, build 
> compiles the packages but discards the resulting object, serving only as a 
> check that the packages can be built.*
>
> *The -o flag forces build to write the resulting executable or object to 
> the named output file or directory, instead of the default behavior 
> described in the last two paragraphs."*
> For me I had the problem the other way 
> <https://groups.google.com/g/golang-nuts/c/JvHa4EEVEQo/m/XNlspgAyAgAJ>: 
> "go build ./..." was happily building the binary when there was only one 
> main package, but stopped working when I added a second.  The solution for 
> me was "go build -o . ./..."
>
> Sorry but I don't know how to make go build with a single main package 
> discard the output.  I'd be inclined to make use of .gitignore
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c9d04c77-006f-468e-9972-4ad4ad94c9ben%40googlegroups.com.

Reply via email to