静态库如何链接到依赖项? [英] How do static libraries do linking to dependencies?

查看:39
本文介绍了静态库如何链接到依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有 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.

这篇关于静态库如何链接到依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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