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: unable to set LDFLAGS -X for a vendored variable #28831

Closed
vearutop opened this issue Nov 16, 2018 · 1 comment
Closed

cmd/link: unable to set LDFLAGS -X for a vendored variable #28831

vearutop opened this issue Nov 16, 2018 · 1 comment

Comments

@vearutop
Copy link
Contributor

@vearutop vearutop commented Nov 16, 2018

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

$ go version
go version go1.11 darwin/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
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/viacheslav.poturaev/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/viacheslav.poturaev/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lb/j0gz8jln36z4frqkrzmkdb0c0000gp/T/go-build187400651=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Tried to set a value to a variable in vendored package by import path.

go run -ldflags "-X github.com/some/lib/pkg/version.Version=1.2.3" main.go

Or

go run -ldflags "-X vendor/github.com/some/lib/pkg/version.Version=1.2.3" main.go

What did you expect to see?

A value of "1.2.3" being assigned to github.com/some/lib/pkg/version.Version.

What did you see instead?

Default value is kept.

The value can be only set with full $GOPATH import path:

go run -ldflags "-X github.com/my/project/vendor/github.com/some/lib/pkg/version.Version=1.2.3" main.go
@ianlancetaylor ianlancetaylor changed the title Unable to set LDFLAGS -X for a vendored variable cmd/link: unable to set LDFLAGS -X for a vendored variable Nov 16, 2018
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Nov 16, 2018

Closing as dup of #25011.

@golang golang locked and limited conversation to collaborators Nov 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.