'invalid value "all -N -l" for flag -gcflags' when go build

Viewed 4237

I want to remote debug Golang bin file with delve. First, I need to compile the .go file:

go build -gcflags='all -N -l' main.go

but the outcome is

invalid value "all -N -l" for flag -gcflags: missing =<value> in <pattern>=<value> usage: build [-o output] [-i] [build flags] [packages] Run 'go help build' for details.

How to solve this problem?

go version: 1.10.3 amd64/linux

1 Answers

How to solve this problem?

$ go build -gcflags='all -N -l' main.go
invalid value "all -N -l" for flag -gcflags: missing =<value> in <pattern>=<value>
usage: go build [-o output] [-i] [build flags] [packages]
Run 'go help build' for details.

Follow the instructions in the error message.

Run 'go help build' for details.

$ go help build

<<SNIP>>

The -asmflags, -gccgoflags, -gcflags, and -ldflags flags accept a
space-separated list of arguments to pass to an underlying tool
during the build. To embed spaces in an element in the list, surround
it with either single or double quotes. The argument list may be
preceded by a package pattern and an equal sign, which restricts
the use of that argument list to the building of packages matching
that pattern (see 'go help packages' for a description of package
patterns). 

<<SNIP>>

Follow the instructions in the help text precisely.

The argument list may be preceded by a package pattern and an equal sign.

For example, for package patterm all: all=.

go build -gcflags='all=-N -l' main.go

References:

Command go: Compile packages and dependencies

Related