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: -ldflags -X does not allow values with spaces #16743

Closed
mediocregopher opened this issue Aug 16, 2016 · 1 comment
Closed

cmd/link: -ldflags -X does not allow values with spaces #16743

mediocregopher opened this issue Aug 16, 2016 · 1 comment

Comments

@mediocregopher
Copy link

mediocregopher commented Aug 16, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
go version go1.7 linux/amd64
  1. What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN="/home/mediocregopher/src/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mediocregopher/src/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build914586157=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
  1. What did you do?
    If possible, provide a recipe for reproducing the error.
    A complete runnable program is good.
    A link on play.golang.org is best.
package main

import "fmt"

var foo string

func main() {
    fmt.Printf("%q\n", foo)
}

Then:

go build -ldflags '-X main.foo="bar baz"' main.go && ./main
  1. What did you expect to see?
"bar baz"
  1. What did you see instead?
# command-line-arguments
usage: link [options] main.o
  -B note
        add an ELF NT_GNU_BUILD_ID note when using ELF
  -C    check Go calls to C code

... etc

The linker doesn't like spaces in the value. In 1.6 this could be worked around by not using the equal sign, but that form is no longer allowed in 1.7

EDIT: Should note, I've tried all combinations of single-quote/double-quote/no-quote I could think of, none seem to work

@mwhudson
Copy link
Contributor

go run -ldflags '-X "main.foo=bar baz"' main.go works for me.

@golang golang locked and limited conversation to collaborators Aug 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants