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/link: -X flag fails when used with non-deprecated = syntax #12152

Closed
joeshaw opened this issue Aug 14, 2015 · 1 comment

Comments

Projects
None yet
3 participants
@joeshaw
Copy link
Contributor

commented Aug 14, 2015

With go 1.5rc1 on darwin/amd64:

Test source:

package main

import "fmt"

var buildTime string

func main() {
    fmt.Println(buildTime)
}
$ go build -ldflags "-X main.buildTime \"$(date -u)\""
# _/tmp/bar
link: warning: option -X main.buildTime Fri Aug 14 19:50:25 UTC 2015 may not work in future releases; use -X main.buildTime=Fri Aug 14 19:50:25 UTC 2015

-x output:

/usr/local/Cellar/go/1.5rc1/libexec/pkg/tool/darwin_amd64/link -o $WORK/_/tmp/bar/_obj/exe/a.out -L $WORK -extld=clang -buildmode=exe -buildid=1583c81ada6eb4c112c3f8767eea388203667aa3 -X main.buildTime "Fri Aug 14 19:51:24 UTC 2015" $WORK/_/tmp/bar.a
$ go build -ldflags "-X main.buildTime=\"$(date -u)\""
# _/tmp/bar
usage: link [options] main.o
...

-x output:

/usr/local/Cellar/go/1.5rc1/libexec/pkg/tool/darwin_amd64/link -o $WORK/_/tmp/bar/_obj/exe/a.out -L $WORK -extld=clang -buildmode=exe -buildid=1583c81ada6eb4c112c3f8767eea388203667aa3 -X "main.buildTime=\"Fri" Aug 14 19:52:14 UTC "2015\"" $WORK/_/tmp/bar.a

The shell quoting is wrong in the latter case: "main.buildTime=\"Fri" Aug 14 19:52:14 UTC "2015\""

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Aug 14, 2015

In -ldflags you have to quote entire options, not parts of options.

This works:

go build -ldflags "-X "main.buildTime=$(date -u)""

@mikioh mikioh changed the title cmd/ld: -X flag fails when used with non-deprecated = syntax cmd/link: -X flag fails when used with non-deprecated = syntax Aug 14, 2015

@golang golang locked and limited conversation to collaborators Aug 22, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.