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

go build can't correctly parse ldflags on go1.10 #25333

Closed
openstacker opened this issue May 10, 2018 · 3 comments
Closed

go build can't correctly parse ldflags on go1.10 #25333

openstacker opened this issue May 10, 2018 · 3 comments

Comments

@openstacker
Copy link

Please answer these questions before submitting your issue. Thanks!

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

go 1.10

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN="/mnt/Gopath/bin"
GOCACHE="/home/feilong/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/feilong/MyWorkspace/workspace_k8s"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="0"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build213708075=/tmp/go-build -gno-record-gcc-switches"

What did you do?

On go1.9.1, when I run command:

go build -ldflags '"-w -s -X 'main.version=c206dbe2'"' -o k8s-keystone-auth cmd/k8s-keystone-auth/main.go

I got this error, see http://paste.openstack.org/show/720640/

But on gov1.10, the build passed. However, the main.version is not set.

What did you expect to see?

I expect to see same behaviour as v1.9.1 if the ldflags can't be welly parsed.

What did you see instead?

The build passed, however the version is not set correctly.

@ianlancetaylor
Copy link
Contributor

For this kind of use you'll need to use -ldflags=all='...'. See https://golang.org/doc/go1.10#build. When you list the files explicitly like this, rather than building a package, the go tool doesn't know which package the -ldflags should apply to.

@openstacker
Copy link
Author

@ianlancetaylor Hi Ian, thanks for the reply. As I mentioned in the original description, though I know in v1.10 I should use another way, I would like to see the same/similar error message like v1.9.1 if the parameter format is not correct. Does that make sense? Thanks again.

@ianlancetaylor
Copy link
Contributor

You should see that same error if you use the same unusual quoting with -ldflags=all='"..."'

@golang golang locked and limited conversation to collaborators May 25, 2019
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