当前位置:网站首页>Does the go compiled executable have dynamic library links?

Does the go compiled executable have dynamic library links?

2022-06-26 09:46:00 wohu1104

Go Quotes from other packages , Is to compile all referenced packages . use ldd Look at a few Go Some compiled binary programs do not use dynamic link libraries . But some of them refer to dynamic link libraries , Why is this ?

answer :Go The default is on CGO_ENABLED Of , namely CGO_ENABLED=1 . But whether the compiled binary program has dynamic links , It depends on what package your program uses . If it is a hello world, Then the compiled program will be a pure static program .

If you rely on network packages or some system packages , For example, use http The package writes a web server, Then the compiled binary program will be a program containing dynamic links .

The reason lies in the current Go Standard library , Some functions have two implementations , One is C The realization of language , One is Go The realization of language .

  • stay CGO_ENABLED When on , Go The linker will link C Language version , So there is the situation of relying on dynamic link library .
  • If you will CGO_ENABLED Set as 0, You recompile the link , that Go The linker will use Go Implementation of version , In this way, you will get a pure static binary program without dynamic links .
原网站

版权声明
本文为[wohu1104]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170549209578.html