无关的图书馆链接

无关的图书馆链接

本文介绍了无关的图书馆链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可能有点愚蠢的问题,因为我很确定自己已经知道答案了.

I have a question which may be somewhat silly because I'm pretty sure I may know the answer already.

假设您有静态库A,动态共享库B和Linux下的程序C.假设库A从库B调用函数,而您的程序从库A调用函数.现在假设C在A中调用的所有函数都没有使用B中的函数.

Suppose you have static library A, and dynamic shared object library B and your program C under linux. Suppose that library A calls functions from library B and your program calls functions from library A. Now suppose that all functions that C calls in A make no use of functions in B.

仅编译A并省略B就足以编译C,而且您的程序C可以在未安装库B的系统上运行吗?

To compile C will it be enough to link just A and omit B and furthermore can your program C be run on a system without library B installed?

推荐答案

如果您的程序在A中调用未引用B的函数,则在链接或加载时都不需要B,前提是假定A中的函数位于单独的编译单元,通常是库.

If your program calls functions in A that don't reference B then B is not required either at link or load time, assuming that the functions in A are in separate compilation units, which is usually the case for a library.

链接器将从C使用的库中提取函数,并且由于它们都不调用B中的函数,因此不需要B.

The linker will pull the functions from the library that C uses and since none of them call functions in B, B will not be needed.

这篇关于无关的图书馆链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 10:51