引用this answer :
There are two Linux C/C++ library types.
Static libraries (
*.a
) are archives of object code which are linked with and becomes part of the application. They are created with and can be manipulated using thear(1)
command (i.e.ar -t libfoo.a
will list the files in the library/archive).Dynamically linked shared object libraries (
*.so
) can be used in two ways.
- The shared object libraries can be dynamically linked at run time but statically aware. The libraries must be available during compile/link phase. The shared objects are not included into the binary executable but are tied to the execution.
- The shared object libraries can be dynamically loaded/unloaded and linked during execution using the dynamic linking loader system functions.
制作动态 库是什么意思 tied to the execution ?
这像Windows manifest files吗允许应用程序加载特定的 dll?
控制.so加载的机制是什么?
必须有这样一种机制,否则“编译的”.so 是唯一允许加载的机制,这违背了使其成为动态的目的?
最佳答案
这意味着该库在链接时可用,因此链接器可以验证您从 .so
引用的函数是否存在于 .so
中。优点是对这些函数的调用对您来说是透明的。换句话说,如果您链接到 .so
和
int foo(double bar);
你可以这样调用它
int res = foo(4.2);
链接器确保 foo
存在,并且它接受一个 double
类型的参数。之后它将调用站点 int res = ...
“链接”到该函数。
在执行期间动态加载/卸载允许您在构建系统上不存在 .so
的情况下进行链接(因此,没有“静态感知”)。作为这种增加的灵 active 的交换,您打开了系统,可能无法在目标 .so
中找到您想要的功能。您的调用序列看起来也比 foo(4.2)
复杂得多,因为您需要完成 dlopen
准备步骤。关于从 .so
调用函数的更多信息在 this Q&A 中.
关于c++ - "dynamically linked at run time but statically aware"- 如何控制加载哪个.so文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40180916/