New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: executables are sometimes named after their module's last element, not directory #27283

spenczar opened this Issue Aug 27, 2018 · 3 comments


None yet
6 participants

spenczar commented Aug 27, 2018

What version of Go are you using (go version)?


Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?

darwin amd64

What did you do?

In a package main's directory (specifically,, I had a go.mod like this:


I then ran GO111MODULE=on go build . from within $GOPATH/src/

I expected an executable named protoc-gen-twirp, because that is the last element of the directory. This is the documented behavior in

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').

Instead, an executable was produced named v5.

However, if I invoke go build with a full path, I get the expected name. GO111MODULE=on go build produces an executable named protoc-gen-twirp.

This is either a documentation error, or a bug.


This comment has been minimized.


mvdan commented Aug 27, 2018

@FiloSottile FiloSottile added this to the Go1.12 milestone Aug 30, 2018


This comment has been minimized.


myitcv commented Sep 7, 2018


export GOPATH=$(mktemp -d)
cd $(mktemp -d)
mkdir hello
cd hello
go mod init
cat <<EOD > main.go

package main

func main() {}
go build .


$ ls
go.mod  main.go  v6


$ go install
$ ls $GOPATH/bin

go install was fixed in #24667; sounds like a similar fix needed for go build.


This comment has been minimized.

gopherbot commented Oct 10, 2018

Change mentions this issue: cmd/go: fix the default build output name for versioned binaries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment