c++ - "dynamically linked at run time but statically aware"- 如何控制加载哪个.so文件?

标签 c++ linux gcc

引用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 the ar(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.

    1. 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.
    2. 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/

相关文章:

c++ - 是否有任何选项可以推迟可变参数模板中函数调用的评估

c++ - xcode 中的 Stray/377

c++ - boolean 计算器如何使用堆栈检查用户输入 C++

linux - 链接时 LD_LIBRARY_PATH 和 -L 有什么区别?

gcc - 如何使用 GCC 编译一个独立的环境?

gcc - SSE 4 popcount 为 16 个 8 位值?

c++ - 如何创建/设计数据结构?

regex - 使用 awk 替换正则表达式模式

python - 有没有办法以编程方式获取 ps 输出?

java - 在 linux 传输错误 202 : bind failed 上执行 jdb