LOCAL_WHOLE_STATIC_LIBRARIES 此变量是 LOCAL_STATIC_LIBRARIES
的变体,表示链接器应将相关的库模块视为完整归档。如需详细了解完整归档,请参阅有关 --whole-archive
标记的 GNU Id 文档。
多个静态库之间存在循环依赖关系时,此变量十分有用。使用此变量构建共享库时,它将强制构建系统将静态库中的所有对象文件添加到最终二进制文件。但是,生成可执行文件时不会发生这种情况。
LOCAL_STATIC_LIBRARIES与LOCAL_WHOLE_STATIC_LIBRARIES的区别
LOCAL_STATIC_LIBRARIES
These are the static libraries that you want to include in your module. Mostly, we use shared libraries, but there are a couple of places, like executables in sbin and host executables where we use static libraries instead.
LOCAL_WHOLE_STATIC_LIBRARIES
These are the static libraries that you want to include in your module without allowing the linker to remove dead code from them. This is mostly useful if you want to add a static library to a shared library and have the static library’s content exposed from the shared library.
总的来说LOCAL_WHOLE_STATIC_LIBRARIES在连接静态连接库的时候不会移除”daed code”,何谓dead code呢,就是调用者模块永远都不会用到的代码段和变量。
可以得到如下的结论:
是否链接到调用者模块 | 使用了静态库的global变量 | 不使用 |
---|---|---|
LOCAL_STATIC_LIBRARIES | Y | N |
LOCAL_WHOLE_STATIC_LIBRARIES | Y | Y |