.o,.a和.so文件有什么区别? [英] What is the difference between .o, .a, and .so files?

查看:89
本文介绍了.o,.a和.so文件有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 .o 是目标文件, .a 是静态库,而 .so 是动态库?它们的物理意义是什么?什么时候可以使用,什么时候不可以使用?

I know .o are object files, .a are static libraries and .so are dynamic libraries? What is their physical significance? When can I use some and when not?

推荐答案

.a 是存档".尽管档案可以包含任何类型的文件,但在GNU工具链的上下文中,它是一个目标文件库(其他工具链,尤其是Windows上的其他工具链,出于相同的目的使用 .lib ,但是格式为这些通常不是通用存档,并且通常特定于工具链).可以从存档中提取单个目标文件,这实际上是链接器使用库时所做的工作.

.a is an "archive". Although an archive can contain any type of file, in the context of the GNU toolchain, it is a library of object files (other toolchains especially on WIndows use .lib for the same purpose, but the format of these is not typically a general purpose archive, and often specific to the toolchain). It is possible to extract individual object files from an archive which is essentially what the linker does when it uses the library.

.o 是一个目标文件.这是被编译为机器代码但未(通常)完全链接的代码-它可能具有未解决的对由单独编译生成的其他对象文件(在库中或单独地)定义的符号的引用.目标文件包含元数据以支持与其他模块的链接,还可以选择用于源代码级的符号调试(例如,在GDB中).同样在Windows上,其他工具链也通常使用扩展名 .obj 而不是 .o .

.o is an object file. This is code that is compiled to machine code but not (typically) fully linked - it may have unresolved references to symbols defined in other object files (in a library or individually) generated by separate compilation. Object files contain meta-data to support linking with other modules, and optionally also for source-level symbolic debugging (in GDB for example). Other toolchains, again typically on Windows, use the extension .obj rather than .o.

.so 是一个共享库(或只是共享库).它在启动程序时动态链接到可执行文件,而不是在构建时静态链接.它允许较小的可执行文件,并且多个可执行文件可以使用一个对象库实例.操作系统API通常是共享库,出于许可原因,它们也经常在GNU中使用,以将LGPL代码与封闭源专有代码分开(例如,我不是律师,对于这种方法的合法性,我不作任何声明.任何特殊情况).与 .o .a 文件不同,应用程序使用的 .so 文件必须在运行时系统上可用.其他系统(通常也是Windows)将 .dll (动态链接库)用于相同的目的.

.so is a shared object library (or just shared library). This is dynamically linked to an executable when a program is launched rather then statically linked at build time. It allows smaller executables, and a single object library instance to be used by multiple executables. Operating system APIs are typically shared libraries, and they are often used also in GNU for licensing reasons to separate LGPL code from closed-source proprietary code for example (I am not a lawyer - I am making no claims regarding the legitimacy of this approach in any particular situation). Unlike .o or .a files, .so files used by an application must be available on the runtime system. Other systems (again typically Windows) use .dll (dynamic link library) for the same purpose.

了解 .o 文件是在 .a 文件中的之前对象代码之前链接的,这可能很有用,例如,如果符号解析为如果 .o 文件满足要求,则不会链接任何库实现-允许您用自己的库替换本质上的库实现,也可以使库实现调用用户定义的代码-例如GUI框架可能会称为应用程序入口点.

It is perhaps useful to understand that .o files are linked before object code in .a files such that if a symbol resolution is satisfied by a .o file, any library implementation will not be linked - allowing you to essentially replace library implementations with your own, and also for library implementations to call user-defined code - for example a GUI framework might call an application entry-point.

这篇关于.o,.a和.so文件有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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