我目前正在学习微服务在线课程,我将小型 Go 应用程序部署到 docker 容器。用于构建二进制文件的长而丑陋的命令行是这样的:
go build --tags netgo --ldflags '-extldflags "-lm -lstdc++ -static"'
到目前为止,我只是用来go install编译我的 go 应用程序。
谁能向我解释这个命令?
蝴蝶刀刀
浏览 408回答 1
1回答
慕标5832272
--tags netgo 用于使用 go lang 网络栈--ldflags设置传递给“go tool link”的标志args 到 ldflags 的值在go tool 链接帮助中有说明-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