How do static libraries do linking to dependencies?(静态库如何链接到依赖项?)
问题描述
假设我有 libA.例如,它依赖于 libSomething,因为 libA 的非内联方法调用 libSomething.h 中的方法这一简单事实.在这种情况下,依赖关系如何联系起来?libA 在编译时是否必须静态链接到 libSomething,或者 libA 的用户(使用 libA 的应用程序)是否需要同时链接到 libA 和 libSomething?
Say I have libA. It depends on, for example, libSomething for the simple fact that a non-inline method of libA makes a call to a method in libSomething.h. How does the dependency link up in this case? Does libA have to statically link to libSomething when it is compiled, or will a user of libA (an application using libA) need to link to both libA and libSomething?
谢谢
推荐答案
静态链接只是将整个项目(函数、常量等)复制到生成的可执行文件中.如果静态库的代码包含对某些共享库项的引用,这些引用将成为生成的可执行文件中的依赖项.如果您链接库而不是可执行文件,则同样如此.
Static linking is just copying the whole items (functions, constants, etc) into the resulting executable. If a static library's code contains references to some shared library items, these references will become dependencies in the resulting executable. The same holds if you link a library instead of executable.
这个话题 讨论它在 Linux 中是如何发生的.
This thread discusses how it happens in Linux.
这篇关于静态库如何链接到依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:静态库如何链接到依赖项?


基础教程推荐
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 使用从字符串中提取的参数调用函数 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01