ar can create an .a file which includes another .a file, such that the output of ar -t whatever.a looks like:

someotherarchive.a
foo.o
bar.o

However, if this archive is then linked, the symbols from an .o in someotherarchive.a will not be accessible by foo.o. This can be resolved by flattening with the T switch to ar when creating, but that also creates a thin archive. Since there does not seem to be a flatten-but-don't-thin option, it's necessary to extract from someotherarchive.a first and then link the .os independently to create something that contains:

otherarchivememberA.o
otherarchivememberB.o
foo.o
bar.o

Raising the question, if putting one .a inside another .a makes it inaccessible, what's the purpose of doing so?

有帮助吗?

解决方案

Presumably this is because ar was historically a general purpose archiving tool, like tar.

In other words, there is no purpose to inaccessibly nesting archives if you are creating static libraries.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top