简体   繁体   中英

What is the meaning of `-X` in `go build -ldflags`'s arguments?

In the documentation of golang, I can't find any explanation about the arguments of -ldflags .

go build -ldflags "-X main.version=${IDE_DATE}-${IDE_VERSION}-${IDE_OS}-${IDE_ARCH}-DEBUG" -o $2 cmd/backend.go

Where can I find the documentatuion about -ldflags ?

ldflags stands for linker flags, and is used to pass in flags to the underlying linker. As per the documentation:

-X importpath.name=value
    Set the value of the string variable in importpath named name to value.
    This is only effective if the variable is declared in the source code either uninitialized
    or initialized to a constant string expression. -X will not work if the initializer makes
    a function call or refers to other variables.
    Note that before Go 1.5 this option took two separate arguments.

Command Link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM