这些 Go 构建标志是什么意思?netgo -extldflags "-lm -lstdc++ -static" '



我目前正在参加一个微服务在线课程,我将小型go应用程序部署到docker容器。构建二进制文件的冗长而丑陋的命令行是这样的:

go build --tags netgo --ldflags '-extldflags "-lm -lstdc++ -static"'

到目前为止,我只是使用go install来编译我的Go应用程序。

谁能向我解释这个命令?

--tags netgo 用于使用 Go lang Network Stack

-

-ldflags 设置传递给"Go 工具链接"的标志

参数对 ldflags 的值在 go 工具链接帮助中进行了解释

-extldflags flags
    Set space-separated flags to pass to the external linker.

在这种情况下,外部链接器是"ld"因此,您可以阅读手册页
每个参数的含义是:

-lm enables linking of the standard math library
-lstdc++ enables linking of the standard c++ library
-static means do not link against shared libraries

最新更新