简体   繁体   English

默认情况下,gcc是否链接到静态或动态标准库?

[英]By default, does gcc link to static or dynamic standard library?

Ex: 例如:

gcc source-file

I think it is dynamic but I'm not sure. 我认为这是动态的,但我不确定。 Is it system dependent? 它是系统依赖的吗?

It is technically system dependent, but on most systems you're likely to develop for, the answer is "dynamic". 它在技术上依赖于系统,但在大多数系统中你可能会开发,答案是“动态的”。

A few systems (mostly very old, embedded, or otherwise specialized) do not support dynamic linking at all , but most developers are unlikely to care about those systems. 少数系统(大多是很老,嵌入或以其他方式专业)不支持动态链接所有,但大多数开发商都不太在意这些系统。 On those systems, the linker will of course default to linking statically (unless whoever did the port screwed up :)). 在这些系统上,链接器当然默认是静态链接(除非那个端口搞砸了:))。

Some systems also do not offer static versions of their standard libraries, so you can't statically link them. 某些系统也不提供其标准库的静态版本,因此您无法静态链接它们。

On many systems (especially any typical Linux system), you probably have a utility called ldd . 在许多系统(尤其是任何典型的Linux系统)上,您可能有一个名为ldd的实用程序。 You can use ldd <file> to check if it's dynamically linked to the standard library (assuming you know for sure what the library is called, it's usually libc though). 您可以使用ldd <file>检查它是否动态链接到标准库(假设您确定该库的名称是什么,它通常是libc )。

Most linkers prefer dynamic libraries to static when linking, but normally they have flags to explicitly specify the behaviour. 大多数链接器在链接时更喜欢动态库到静态,但通常它们具有标记以明确指定行为。 It's definitely system dependent - check your linker documentation for details. 它绝对取决于系统 - 请查看链接器文档以获取详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM