Linux .so 和 .a 文件有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12293530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what is the difference between .so and .a files?
提问by rajshenoy
I am trying to compile a 3rd party library( on linux) and see that it is generating libsomething.a files I have my other libraries which are .so file
我正在尝试编译一个 3rd 方库(在 linux 上)并看到它正在生成 libsomething.a 文件我有我的其他库,它们是 .so 文件
But it appears that even .a is shared library and can be used just like a .so lib
但似乎 .a 也是共享库,可以像 .so lib 一样使用
So is there any difference between the two ? or they are just same with different naming convention.
那么两者之间有什么区别吗?或者它们只是具有不同的命名约定。
采纳答案by rajshenoy
But it appears that even .a is shared library
但似乎 .a 也是共享库
Nope, it's a static library.
不,它是一个静态库。
and can be used just like a .so lib
并且可以像 .so lib 一样使用
If you mean linking to it, then yes. But you can't dlopen() an .a file which you could do with an .so file.
如果您的意思是链接到它,那么是的。但是你不能 dlopen() 一个 .a 文件,而你可以用一个 .so 文件来做。
You can always ask our old friend Uncle Gto answer your questions.
您可以随时请我们的老朋友G叔来回答您的问题。
回答by gks
A .a
file is a static library, while a .so
file is a shared object dynamic librarysimilar to a DLL
on Windows.
一个.a
文件是一个静态库,而.so
文件是一个共享对象动态库类似于DLL
在Windows上。
A .a
can included as partof a program during the compilation& .so
can imported, while a program loads.
阿 .a
可包括作为部分的过程中的程序汇编&.so
可以进口,而程序加载。
回答by William Pursell
When you link against the *.a
, the code from the library is included in the executable itself and the executable can be run without requiring the *.a
file to be present. When you link against the *.so
, that is not the case and the *.so
file must be present at runtime.
当您链接到 时*.a
,库中的代码包含在可执行文件本身中,并且可执行文件可以运行而无需*.a
文件存在。当您针对 链接时*.so
,情况并非如此,并且该*.so
文件必须在运行时存在。