Skip to content
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: the -o option does not append .exe suffix to the compiled executable #59790

Closed
shanoaice opened this issue Apr 24, 2023 · 7 comments
Closed
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows Unfortunate WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@shanoaice
Copy link

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

$ go version
go version go1.20.3 windows/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Haoqing Chen\AppData\Local\go-build
set GOENV=C:\Users\Haoqing Chen\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Haoqing Chen\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Haoqing Chen\go
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=C:\Users\Haoqing Chen\scoop\apps\go\current
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Users\Haoqing Chen\scoop\apps\go\current\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.20.3
set GCCGO=gccgo
set GOAMD64=v3
set AR=ar
set CC=clang
set CXX=clang++
set CGO_ENABLED=0
set GOMOD=D:\projects\sing-box\go.mod
set GOWORK=
set CGO_CFLAGS=-g -O3 -march=native -flto=thin
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O3 -march=native -flto=thin
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-g -O3 -march=native -flto=thin
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\HAOQIN~1\AppData\Local\Temp\go-build2509538014=/tmp/go-build -gno-record-gcc-switches

What did you do?

Tried to compile any go program and specify an executable name by -o option, such as go build -o hello ./hello-world.go

What did you expect to see?

The executable name should be hello.exe. clang and gcc both add the .exe suffix automatically.

What did you see instead?

The executable name is simply hello, which will not be recognized by Windows as an executable file.

@dmitshur
Copy link
Contributor

CC @bcmills, @matloob.

@dmitshur dmitshur added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Apr 24, 2023
@dmitshur dmitshur added this to the Backlog milestone Apr 24, 2023
@seankhliao
Copy link
Member

This was intentional behaviour #3190 (comment)

@bcmills
Copy link
Member

bcmills commented Apr 24, 2023

Yes, this looks like it's working as documented. The -o flag names a file, not a basename of the file.

Is there some reason you cannot pass -o hello.exe when compiling on Windows?

@bcmills bcmills added Unfortunate OS-Windows WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Apr 24, 2023
@bshephar
Copy link

I think automagically appending file suffix in this case would not be ideal. I personally, would prefer to see the -o option output exactly what I provide it without having to account for arbitrary OS specific extension differences in behaviour. I think it's easy enough to just provide -o blah.exe as suggested by bcmills if you're working on Windows.

My two cents anyway.

@shanoaice
Copy link
Author

shanoaice commented Apr 25, 2023

Yes, this looks like it's working as documented. The -o flag names a file, not a basename of the file.

Is there some reason you cannot pass -o hello.exe when compiling on Windows?

Well, I personally feels a bit awkward to write separate Makefile targets for Windows and Unix-like systems that outputs a binary to a specific path. I feel like if clang and gcc does it on Windows, it is odd to not have the same behavior for go. After all, having an executable that does not have an .exe suffix on Windows is pointless.

@jbaryy708

This comment was marked as spam.

@seankhliao
Copy link
Member

.exe is not the only possible extension on windows for executables, and it is possible to execute binaries without extensions at all.

As before, I don't think we want to be changing this as it will make the command less consistent and possibly break existing users.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows Unfortunate WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants