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

os/exec: pass more than 1 ldflags #33581

Closed
pjebs opened this issue Aug 11, 2019 · 2 comments
Closed

os/exec: pass more than 1 ldflags #33581

pjebs opened this issue Aug 11, 2019 · 2 comments

Comments

@pjebs
Copy link
Contributor

pjebs commented Aug 11, 2019

I'm using Go 1.10 in windows:

For some reason it appears as if -ldflags doesn't allow combining flags when used with exec.CommandContext.

cmd = exec.CommandContext(ctx, "go", "build", "-o", outputPath, "-ldflags=-s", "-ldflags=-w", "-ldflags \"-H windowsgui\"", goFilePath)
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=%s", "GOOS", "windows"))

cmd.CombinedOutput()

The later ldflag flag seems to overwrite the prior.

@ianlancetaylor
Copy link
Contributor

That's how cmd/go works. You pass a single -ldflags option, not multiple ones. That is true on the command and line and it is true when using exec.CommandContext. See the discussion of ldflags and friends at https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies .

@pjebs
Copy link
Contributor Author

pjebs commented Nov 24, 2019

@golang golang locked and limited conversation to collaborators Mar 7, 2021
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