Go是否依赖于C运行时? [英] Does Go depend on C runtime?

查看:69
本文介绍了Go是否依赖于C运行时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到信息golang是否依赖于c运行时?如果依赖它,它是否会在go-binary中静态编译,以使Go-app可以在任何地方工作而无需依赖?

I can't find info does golang depend on c runtime? If it's depend on it is it's statically compiled in go-binary to make Go-app work everywhere without dependences?

此处是有关什么是C运行库

推荐答案

如果您要谈论的是Go编译器提供的可执行文件,那么答案是是或否,这取决于":

If you're talking about executable files provided by a Go compiler, then the answer is "yes or no—it depends":

在大多数情况下,生成的可执行程序取决于C运行时库.

In most cases, the resulting executable program does not depend on a C run-time library.

但是,在某些情况下,某些平台上的C运行时库是动态链接到的.特别是Go版本<在使用DNS解析的Linux上为1.5:运行时取决于平台的 libc 实现来处理此类解析.在1.5版中,此内容已被修改.

However, on some platforms under certain circumstances the C runtime library gets dynamically linked in. In particular, this was the case with Go versions < 1.5 on Linux when DNS resolution was used: the runtime depended on the platform's libc implementation to handle such resolution. In 1.5 this has been reworked.

另一种可能的情况是(IIRC)Solaris,它没有提供直接访问内核的系统调用的稳定方法,并且

Another possible case is (IIRC) Solaris which provides no stable way to access the kernel's syscalls directly and requires routing these calls through the platform's libc.

还有另一种情况:使用 cgo ,这是Go代码与外部C代码接口的一层.使用 cgo 可以使您的Go程序依赖于C运行时.请注意,您可能不会直接使用 cgo ,但是您可能正在使用的一个或多个第三方程序包可以使用 cgo ,并且— transitively—您的程序最终取决于C运行时库.

There is another case: using cgo which is a layer to interface Go code with foreign C code. Using cgo makes your Go program depend on the C runtime. Note that you might not use cgo directly but one or more of the third-party packages you might be using can use cgo, and—transitively—your program ends up depending on the C runtime library.

这篇关于Go是否依赖于C运行时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆