go build时标志-gcflags的“无效值“all -N -l”

Ala*_*n42 2 go

我想用 delve 远程调试 Golang bin 文件。首先,我需要编译 .go 文件:

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

但结果是

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.

如何解决这个问题呢?

转到版本:1.10.3 amd64/linux

pet*_*rSO 7

如何解决这个问题呢?

$ 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.
Run Code Online (Sandbox Code Playgroud)

按照错误消息中的说明进行操作。

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>>
Run Code Online (Sandbox Code Playgroud)

严格按照帮助文本中的说明进行操作。

参数列表前面可能有一个包模式和一个等号。

例如,对于包patterm allall=

go build -gcflags='all=-N -l' main.go
Run Code Online (Sandbox Code Playgroud)

参考:

命令 go编译包和依赖项