What do these Go build flags mean? netgo -extldflags “-lm -lstdc++ -static”'

孤者浪人 提交于 2020-06-24 05:10:28

问题


I'm currently taking a microservice online course where I deploy small go apps to docker containers. The long and ugly command line to build the binaries is this one:

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

till now I just used go install to compile my go app.

Can anyone explain this command to me?


回答1:


--tags netgo is used to use go lang network stack

--ldflags sets the flags that are passed to 'go tool link'

The value of the args to ldflags is explained in the go tool link help

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

In this case the external linker is 'ld' so you can read the man page for it
Meaning of each of the arguments is:

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


来源:https://stackoverflow.com/questions/37630274/what-do-these-go-build-flags-mean-netgo-extldflags-lm-lstdc-static

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!