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
I am migrating from Go 1.4 to Go 1.5. When I build my app, the compiler emits a warning that my -ldflags syntax is likely to be deprecated, and offers a misleading suggestion to correct the warning. My use case is a -X -ldflags value that contains spaces.
$ go build -ldflags "-X main.buildInfo 'Version: 2.9, commitID: 4d203fa, build date: Tue Aug 25 19:54:19 PDT 2015, SDK: go version go1.5 darwin/amd64'" -o stashkins-darwin-amd64
# github.com/xoom/stashkins
link: warning: option -X main.buildInfo Version: 2.9, commitID: 4d203fa, build date: Tue Aug 25 19:54:19 PDT 2015, SDK: go version go1.5 darwin/amd64 may not work in future releases; use -X main.buildInfo=Version: 2.9, commitID: 4d203fa, build date: Tue Aug 25 19:54:19 PDT 2015, SDK: go version go1.5 darwin/amd64
If I take a variant of the warning advice, I get
$ go build -ldflags -X main.buildInfo='Version: 2.9, commitID: 4d203fa, build date: Tue Aug 25 19:54:19 PDT 2015, SDK: go version go1.5 darwin/amd64' -o stashkins-darwin-amd64
can't load package: package main.buildInfo=Version: 2.9, commitID: 4d203fa, build date: Tue Aug 25 19:54:19 PDT 2015, SDK: go version go1.5 darwin/amd64: cannot find package "main.buildInfo=Version: 2.9, commitID: 4d203fa, build date: Tue Aug 25 19:54:19 PDT 2015, SDK: go version go1.5 darwin/amd64" in any of:
/usr/local/go/src/main.buildInfo=Version: 2.9, commitID: 4d203fa, build date: Tue Aug 25 19:54:19 PDT 2015, SDK: go version go1.5 darwin/amd64 (from $GOROOT)
/Users/mpetrovic/Projects/go/src/main.buildInfo=Version: 2.9, commitID: 4d203fa, build date: Tue Aug 25 19:54:19 PDT 2015, SDK: go version go1.5 darwin/amd64 (from $GOPATH)
can't load package: package -o: cannot find package "-o" in any of:
/usr/local/go/src/-o (from $GOROOT)
/Users/mpetrovic/Projects/go/src/-o (from $GOPATH)
can't load package: package stashkins-darwin-amd64: cannot find package "stashkins-darwin-amd64" in any of:
/usr/local/go/src/stashkins-darwin-amd64 (from $GOROOT)
/Users/mpetrovic/Projects/go/src/stashkins-darwin-amd64 (from $GOPATH)
Fiddling around with the quotes, I find this invocation works, which the warning did not help me arrive at:
$ go build -ldflags '-X "main.buildInfo=Version: 2.9, commitID: a03e9a7, build date: Tue Aug 25 20:51:38 PDT 2015, SDK: go version go1.5 darwin/amd64"' -o stashkins-darwin-amd64
The text was updated successfully, but these errors were encountered:
ianlancetaylor
changed the title
Compiler gives misleading advice on new -ldflags option when option contains spaces
cmd/link: Linker gives misleading advice on new -ldflags option when option contains spaces
Aug 26, 2015
Thanks to Ian Taylor for responding to a user on go-nuts list. That's where I found the solution, and wanted to capture it here for a fix for posterity.
It's not possible to guess what quoting you need. The linker doesn't know. We could make the message less specific by saying
-X <name> <value> may not work in future releases; use -X <name>=<value>
but that's much less helpful. At least with the specifics you can try to grep for the name or value to find where it came from.
rsc
changed the title
cmd/link: Linker gives misleading advice on new -ldflags option when option contains spaces
cmd/link: linker gives misleading advice on new -ldflags option when option contains spaces
Nov 5, 2015
I am migrating from Go 1.4 to Go 1.5. When I build my app, the compiler emits a warning that my -ldflags syntax is likely to be deprecated, and offers a misleading suggestion to correct the warning. My use case is a -X -ldflags value that contains spaces.
If I take a variant of the warning advice, I get
Fiddling around with the quotes, I find this invocation works, which the warning did not help me arrive at:
The text was updated successfully, but these errors were encountered: